Jump between apps for iOS app development

Source: Internet
Author: User

    • Brief introduction
    • Configuration and implementation
    • Determine how the application starts

First, Introduction

In the most practical project development, we will inevitably encounter situations where we need to jump from one application to another. Sharing, for example, is actually a jump between applications. But sometimes we need to implement our own two app jumps so that we can promote our other apps. This time we need to use UIApplication's OpenURL: The method

Second, the configuration

1?? Registering a custom URL

The app that was launched first needs to register a custom URL protocol with the iphone. This is done in the Info.plist file of your project folder

1. Right-click, select "Add Row", key value Select "URL Types"
2. 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.open.url").
3. Add a line under "Item 0".
4. Select "URL schemes" as key.
5. Enter your URL protocol name (for example "openurl1://" should be written "OpenURL"). If necessary, you can add multiple protocols here.

Graphic:

2?? Part of the code (in another program)

- (void) viewdidload{[Super Viewdidload]; UIButton*BTN =[UIButton Buttonwithtype:uibuttontypecustom]; Btn.frame= CGRectMake ( -, -, -, -); [BTN Settitle:@"Test 123"Forstate:uicontrolstatenormal];    [btn Settitlecolor:[uicolor Blackcolor] forstate:uicontrolstatenormal]; Btn.titleLabel.font= [Uifont systemfontofsize:14.0];    [Btn Setbackgroundcolor:[uicolor redcolor];;        [Btn addtarget:self Action: @selector (Btnclick) forcontrolevents:uicontroleventtouchupinside]; [Self.view addsubview:btn];}- (void) btnclick{Nsurl* myurl_app_a = [Nsurl urlwithstring:@"openurl1://"]; if([[[UIApplication sharedapplication] canopenurl:myurl_app_a]) {NSLog (@"Canopenurl");    [[UIApplication sharedapplication] openurl:myurl_app_a]; }}

Iii. judging the starting mode of application

-(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (nsdictionary *) launchOptions

By using the callback method inside the Appdelegate, you can determine how the application will start. Launchoptions contains the parameters we need.

Description: When the application starts, the application launches the portal. Executes only once when the application starts. The application parameter is used to obtain the state, variable, etc. of the application, and it is worth noting the dictionary parameter: (nsdictionary *) launchoptions, which stores the reason for the program to start.
1. If the user starts directly, no data is in the lauchoptions;
2. If the other application through OpenURL: Start, then the Uiapplicationlaunchoptionsurlkey corresponding object is the boot URL (nsurl), Uiapplicationlaunchoptionssourceapplicationkey the bundle ID of the source application that corresponds to the startup (NSString);
3. If initiated by local notification, the Uiapplicationlaunchoptionslocalnotificationkey corresponds to the local notification object (uilocalnotification) for the launch application;
4. If initiated by remote notification, the Uiapplicationlaunchoptionsremotenotificationkey corresponds to the remote notification information userinfo (nsdictionary) that initiates the application;
Other keys also have Uiapplicationlaunchoptionsannotationkey,uiapplicationlaunchoptionslocationkey,
Uiapplicationlaunchoptionsnewsstanddownloadskey. If you want to make some distinctions at startup, you need to do this in the code below. For example, an app can be picked up by some other app (as a sub-app for that app), and to achieve a single sign-on, you need to make reasonable authentication in the boot code and skip the login
-(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (Nsdictionary *) launchoptions{NSLog (@"%@", launchoptions); Nsurl*url =[Launchoptions Objectforkey:uiapplicationlaunchoptionsurlkey]; if(URL) {} nsstring*bundleid =[Launchoptions Objectforkey:uiapplicationlaunchoptionssourceapplicationkey]; if(Bundleid) {} uilocalnotification* Localnotify =[Launchoptions Objectforkey:uiapplicationlaunchoptionslocalnotificationkey]; if(localnotify) {} nsdictionary* UserInfo =[Launchoptions Objectforkey:uiapplicationlaunchoptionsremotenotificationkey]; if(userInfo) {}returnYES;}

Jump between apps for iOS app development

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.