In iOS, implementing an app to launch another application, using UIApplication's OpenURL: Method can be implemented, here is the example of test jumping to test02. (These two projects need to be created first)
Registering a Custom URL protocol (in test)
The app that was launched first needs to register a custom URL protocol with the iphone. This is done in the Info.plist file.
1. Right-click and select "Add Row"
2. Key value Select "URL Types"
3. Open the Item 0″ and add a URL identifier for the key. Can be any value, but it is recommended to use "anti-domain name" (for example, "Com.fcplayer.test").
4. Add a line under "Item 0".
5. Select "URL schemes" as key.
6. Enter your URL protocol name (e.g. "test://" should be written "test"). If necessary, you can add multiple protocols here.
The operation is as follows:
Accessing a custom URL (in test02) launches another application in the main application by accessing the custom URL: (test is already installed, this code is written in another application, such as test02)
Put it where you need it, call it.
Nsurl * Urlstr = [Nsurl urlwithstring:@ "test://x=100"];//followed by parameters
if ([[[UIApplication sharedapplication] canopenurl:urlstr]) {
NSLog (@ "can go to test");
[[UIApplication sharedapplication] openurl:urlstr];
}else{
NSLog (@ "Can not go to test!!!!! ");
}
Custom processing URL (in test)Sometimes we need to send parameters to another application in addition to booting, which can also be done through custom URLs, such as:
test://
Test://com.company.test
test://config=1&abar=2
In this case, we have to do the custom processing in the launch application, and implement the message in delegate (Cocos2d added in appdelegate), for example:
-(BOOL) Application: (UIApplication *) Applicationhandleopenurl: (nsurl*) URL {//do something withthe URL here}
In general, we parse the URL from the parameter to display it in the view or store it in the userpreference. The following example stores the URL as a URL variable in user preference or prints it out:
-(BOOL) Application: (UIApplication *) application Handleopenurl: (nsurl *) URL
{
if (!url) {return NO;}
NSString *urlstring = [url absolutestring];
NSLog (@ "%@", urlstring);
[[Nsuserdefaults Standarduserdefaults] setobject:urlstring forkey:@ "url"];
[[Nsuserdefaults standarduserdefaults] synchronize];
return YES;
}
IOS---Jump and pass data between apps via OpenURL