Project configuration Implementation open a third-party app

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.