1. Requirements: We create two projects for TestDemo1 Ho TestDemo2, now need to TestDemo1 in a button to open the TESTDEMO2 program, the following configuration is required;
2. Configuration information: First configure the plist file in TestDemo2:
As shown in: Set URL schemes to music (URL schemes recommendations are lowercase, because later when the data is received, case-insensitive, all lowercase), url identifier optional
Add the following method to the Appdelegate in TestDemo2
//Handling URL Requests-(BOOL) Application: (UIApplication *) application Handleopenurl: (Nsurl *) url{NSLog (@"%@", URL); if([[URL scheme] isequaltostring:@"Music"]) { //Working with linksNSString *text =[[URL host] stringbyreplacingpercentescapesusingencoding:nsutf8stringencoding]; Uialertview*myalert = [[Uialertview alloc]initwithtitle:@"New News"Message:textDelegate: Self Cancelbuttontitle:@"I see."Otherbuttontitles:nil]; [Myalert show]; returnYES; } returnNO;}
3. Then configure the plist file in the TestDemo1:
TestDemo1 to open the TESTDEMO2 program can call the following demo:
NSString *telstr =@"music://test";//you need to open the app to configure this ProtocolNsurl*url =[Nsurl Urlwithstring:telstr]; UIApplication*app =[UIApplication sharedapplication]; BOOL CanOpen=[app Canopenurl:url];if(CanOpen) {//There is an app installedBOOL IsOpen=[app Openurl:url]; NSLog (@"opened the app%d.", IsOpen);} Else{//No apps installed//To open a URL by using a browser}
4. Add: If you use an emulator, you may get an error:
LaunchServices:ERROR:There is no registered handler for URL scheme xxx
It is easy to misunderstand that you always think you are missing something is not configured, most likely the problem is because the simulator is not installed XXX so will be caused. It can be replaced by a real machine test.
Project configuration Implementation open a third-party app