Reference: http://www.2cto.com/kf/201401/274753.html
Http://blog.sina.com.cn/s/blog_a170e5c80101gsdj.html
http://blog.csdn.net/perfect_promise/article/details/7793735
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:
7. Two item URL identifier cannot be the same, and the URL schemes of item 0 cannot be the same, this needs to be noted .
Accessing the custom URL (in test02)
Launch another application in the main application by accessing the custom URL: (test is installed, this code is written in another application, such as test02)
-(void) viewdidload {
[Super viewdidload];
UIButton *btn = [UIButton buttonwithtype:uibuttontypecustom];
Btn. Frame = CGRectMake (+, +, + );
Btn. backgroundcolor = [uicolor redcolor];
[Btn addTarget:self action:@selector(onbtnclick) forcontrolevents: UIControlEventTouchUpInside];
[self. View addsubview: btn];
}
-(void) onbtnclick{
nsurl * urlstr = [nsurl urlwithstring:@ "test://x=100"]; The following is a parameter
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://config=1&abar=2
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:
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 *) application OpenURL: (nsurl *) URL sourceapplication: ( nsstring *) sourceapplication annotation: (ID) annotation{
if(!url) {
return NO;
}
nsstring *urlstring = [url absolutestring];
NSLog(@ "%@", urlstring);
return YES;
}
Methods such as calling map phones
How to use OpenURL:
View Plaincopy Toclipboardprint?
[[UIApplication sharedapplication] Openurl:[nsurl urlwithstring:appstring]];
Among the system's appstring are:
1.Map Http://maps.google.com/maps?q=Shanghai
2.Email Mailto://[email protected]
3.Tel tel://10086
4.MSG sms://10086
OpenURL can help you run Maps,sms,browser,phone and even other applications. This is a piece of code that I often need to use in iphone development, and it's just a single line.
-(ibaction) Openmaps {
Open map
Nsstring*addresstext = @ "Beijing";
@ "1Infinite Loop, Cupertino, CA 95014";
Addresstext =[addresstextstringbyaddingpercentescapesusingencoding:nsasciistringencoding];
Nsstring*urltext = [nsstringstringwithformat:@ "http://maps.google.com/maps?q=%@", Addresstext];
NSLog (@ "urltext===============%@", urltext);
[[Uiapplicationsharedapplication] Openurl:[nsurl Urlwithstring:urltext];
}
-(ibaction) Openemail {
Open mail/Fire off a email to Apple support
[[UIApplication sharedapplication]openurl:[nsurl urlwithstring:@ "Mailto://[email protected]"];
}
-(ibaction) Openphone {
Dial number
Callgoogle 411
[[UIApplication sharedapplication] openurl:[nsurl urlwithstring:@ "tel://8004664411"];
}
-(ibaction) opensms {
Open sms
Text Togoogle SMS
[[UIApplication sharedapplication] openurl:[nsurl urlwithstring:@ "sms://466453"];
}
-(ibaction) Openbrowser {
Open your browser
Lanuch any IPhone developers fav site
[[UIApplication sharedapplication] openurl:[nsurl urlwithstring:@ "http://itunesconnect.apple.com"];
}
Call Google Maps inside iphone program
Use the Cllocationmanager class, Mkmapview. and achieve <MKMapViewDelegate,CLLocationManagerDelegate>
Initialize Cllocationmanager,cllocationmanager to get current geographic coordinates
Locmanager=[[cllocationmanager Alloc]init];
[Locmanager setdelegate:self];
Set accuracy
[Locmanager Setdesiredaccuracy:kcllocationaccuracybest];
[Locmanager startupdatinglocation];
After execution, the proxy method is automatically invoked:
Introduction to IOS OpenURL usage