iOS Inter-program Communication
Last Update:2016-03-26
Source: Internet
Author: User
<span id="Label3"></p><span style="font-family: HannotateSC-W7; font-size: large;"><span style="font-family: HannotateSC-W7; font-size: large;"><strong>Inter-program Communication</strong></span></span>1 Set the program identification, the name of their own,<p><p></p></p>2 Add this line of code where you want to jump<p><p>UIApplication sharedapplication] Openurl:[nsurl urlwithstring:@ "producttwo:"];</p></p><p><p>Example: <strong>:(call OpenURL</strong> <strong>in one engineering program</strong> )</p></p><pre class="brush:objc;gutter:true;"><pre class="brush:objc;gutter:true;"> viewcontroller.m// inter-program Communication oneproduct//// Created by Dllo on 16/3/24.// copyright©2016 year Haiteng. All rights reserved.//#import "ViewController.h" @interface viewcontroller () @end @implementation viewcontroller-(void ) viewdidload { [super viewdidload]; Self.view.backgroundColor = [uicolor graycolor];} -(void) touchesbegan: (nsset<uitouch *> *) touches withevent: (uievent *) event{ //producttwo: (your own project Name) name= Xx&age=xx (you want to pass the parameters with & connection Multi-parameter) //note: The parameter cannot have Chinese [[uiapplication sharedapplication] openurl:[nsurl urlwithstring:@ "producttwo://name=xx&age=xx"]; /* LaunchServices:ERROR:There is no registered handler for URL scheme producttwo inter-program communication: The premise is that two apps on the phone exist simultaneously <c12> */} @end </c12></pre></pre><p><p>3 then the event received accordingly, you will receive such a hint that you have succeeded</p></p><p><p></p></p><p><p></p></p><p><p><strong><span style="color: #ff2600;">Note</span> :</strong></p></p><p><p>/*</p></p><p><p>LaunchServices:ERROR:There is no registered handler for URL scheme producttwo</p></p><p><p>Inter-program communication: The premise to ensure that two apps on the phone exist simultaneously</p></p><p><p>*/</p></p><p><p><span style="color: #ff2600;">Of course it's just that, but there's nothing soft, usually we use communication between programs to pass Values.</span></p></p><p><p></p></p><p><p><span style="color: #aa7942;">in <strong>both <span style="font-family: Menlo;">programs</span> <span style="font-family: Menlo; font-size: large;">:(</span> </strong> Appdelegate<strong><span style="font-family: Menlo; font-size: large;">)</span></strong></span></p></p><pre class="brush:objc;gutter:true;">Appdelegate.m//inter-program communication twoproduct////Created by Dllo on 16/3/24.//copyright©2016 year Haiteng. All rights reserved.//#import "AppDelegate.h" @interface appdelegate () @end @implementation appdelegate-(BOOL) Application: (uiapplication *) Application didfinishlaunchingwithoptions: (nsdictionary *) launchOptions {//Override Point for customization after application Launch. Return YES;} ios9.0 (currently obsolete)//-(BOOL) application: (uiapplication *) application handleopenurl: (nsurl *) url{//return yes;//}// ios9.0 recommend this method (most recently, when the program one jumps to me, in this method, I can accept the value it passes over to do Something)-(BOOL) application: (uiapplication *) app openURL: (nsurl *) URL options: (nsdictionary<nsstring *,id> *) options{//decoding nsstring *recetext = [url.host STRINGBYREMOVINGP ercentencoding]; NSLog (@ "%@", recetext); Print to see the value passed by the one program//if you want to go back to Oneproduct executable This method (also write OpenURL method in the appdelegate of the Oneproduct project to get the parameters I wear Back) [self performselect Or: @selector (gobackoneproduct:) Withobject:nil afterdelay:2]; Return YES;} -(void) GoBAckoneproduct: (id) object{[[uiapplication sharedapplication] openurl:[nsurl urlwithstring:@ "ProductOne://name= Twoproductsenddata&age=xx "];} @end</pre><p><p></p></p>At this point you will see the print in both programs (you are Successful)<p><p></p></p><p><p>Summarize:</p></p><p><p>To be blunt, call this code [[uiapplication sharedapplication] openurl:[nsurl urlwithstring:@ "productone://name=twoproductsenddata &age=xx "];</p></p><p><p><span style="color: #0433ff;">Jump by URL schemes identity</span></p></p><p><p>iOS Inter-program Communication</p></p></span>