IOS app development-jump between applications (using WeChat and other third-party shared login), ios jump

Source: Internet
Author: User

IOS application development-jump between applications (using third-party shared login), ios jump
 

  • Introduction
  • Configuration and implementation
  • Determine the application startup Method
   

I. Introduction

 

In most practical project development, we will inevitably encounter situations where we need to jump from one application to another. For example, sharing is actually a jump between applications. However, sometimes we need to jump between our two applications to promote our other applications. In this case, we need to use the openURL: Method of UIApplication.

   

Ii. Configuration

 

Register a custom URL

 

First, the started application needs to register a custom URL protocol with the iPhone. This is done in the info. plist file in your project folder.

 

1. Right-click and select "Add Row". Select "URL types" for the Key value"
2. Open "Item 0" and add a URL identifier for the key. It can be any value, but we recommend that you use "anti-domain name" (for example, "com. open. url ").
3. Add a row under Item 0.
4. Select "URL Schemes" as the Key.
5. Enter Your URL protocol name (for example, "openurl1: //" should be written as "openurl "). If necessary, you can add multiple protocols here.

 

Illustration:

 

 

Pipeline Code (in another program)

 
-(Void) viewDidLoad {[super viewDidLoad]; UIButton * btn = [UIButton buttonWithType: UIButtonTypeCustom]; btn. frame = CGRectMake (100,100,120, 50); [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];}
   

3. determine the application startup Method

 
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
 

You can use the callback method in AppDelegate to determine the application startup method. LaunchOptions contains the required parameters.

 
Description: This interface is used to start an application. It is executed only once when the application is started. The application parameter is used to obtain the state and variable of the application. It is worth noting that the dictionary parameter (NSDictionary *) launchOptions indicates the reason why the storage program starts.
 
1. If the user starts it directly, there is no data in lauchOptions;
2. If other applications are started through openURL:, the object corresponding to UIApplicationLaunchOptionsURLKey is the startup URL (NSURL), and the bundle ID (NSString) of the source application corresponding to the UIApplicationLaunchOptionsSourceApplicationKey );
3. If a local notification is enabled, the UIApplicationLaunchOptionsLocalNotificationKey corresponds to the local notification object (UILocalNotification) for the application to be started );
4. If a remote notification is enabled, the UIApplicationLaunchOptionsRemoteNotificationKey corresponds to the remote Notification Information userInfo (NSDictionary) of the application );
 
Other keys include UIApplicationLaunchOptionsAnnotationKey and UIApplicationLaunchOptionsLocationKey,
UIApplicationLaunchOptionsNewsstandDownloadsKey. If you want to make some distinction at startup, you need to process the following code. For example, an application can be called by another application (as a sub-Application of the Application). To achieve single-point logon, you must make a reasonable verification at the startup code and skip the logon.
 
- (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){}        return YES;}
Finally, during development, canOpenURL: failed for URL: "ABC: // app/******/"-error: "This app is not allowed to query for scheme ABC" error,

Because IOS controls user privacy and prohibits scanning system information, the canOpenURL method is used to determine whether a user installs a specific app.-canOpenURL: failed for URL: "ABC: // app/*******/"-error:" This app is not allowed to query for scheme ABC "error,

At the same time, NO is returned, and NO response is returned directly through openUrl. For more information, see Quick Take on iOS 9 URL Scheme Changes.

It is easy to modify. You only need to add the ABC whitelist to plist, for example:

<Key> LSApplicationQueriesSchemes </key>

<Array>

<String> ABC </string>

</Array>

 

Related Article

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.