IOS-(jump between two apps)

Source: Internet
Author: User
Tags reserved

One program to jump to another program. needs to be modified in the plist file of the target program:

Open info.plist, add a URL types

Expand the URL types, and then expand Item0 to change the URL under Item0 to URL Scheme

Expand URL Scheme To modify the contents of the ITEM0 to Secondapp (this is the key for the jump)

If you don't say more, start with the following steps:

First, create two projects, the first Firstapp, the second Secondapp

The first APP info.plist need to set the key (URL) and whitelist

Next, we'll deal with the second Secondapp project.

After the two projects are set up, the next code

The first Firstapp project

//

Viewcontroller.m

Firstapp

//

Created by Luorende on 16/8/25.

COPYRIGHT©2016 year Luorende. All rights reserved.

//

#import "ViewController.h"

@interface Viewcontroller ()

@end

@implementation Viewcontroller

-(void) Viewdidload {

[Super Viewdidload];

UIButton * button = [UIButton buttonwithtype:uibuttontypecustom];

Button.frame = CGRectMake (100, 100, 200, 50);

Button.backgroundcolor = [Uicolor Darkgraycolor];

[Button settitle:@ "jumps to Secondapp" forstate:uicontrolstatenormal];

Button.titleLabel.font = [Uifont systemfontofsize:20];

[Button addtarget:self action: @selector (Clickbutton:) forcontrolevents:uicontroleventtouchupinside];

[Self.view Addsubview:button];

}

Jump to Secondapp

-(void) Clickbutton: (UIButton *) button{

NSLog (@ "executed click event");

Previously configured whitelist, is the need to jump each other app's key, that is, the other set URL

NSString * urlstr = @ "Secondapp://xxxxx";

Nsurl * url = [Nsurl urlwithstring:urlstr];

You can make a judgment here first.

if ([[UIApplication Sharedapplication]canopenurl:url]) {

[[UIApplication sharedapplication] openurl:url];

}else{

NSLog (@ "Application not Installed");

}

}

Jump to the App Store

-(void) abc{

[[UIApplication Sharedapplication]openurl:[nsurl urlwithstring:@ ']];

[[UIApplication Sharedapplication]openurl:[nsurl urlwithstring:@ ']];

}

Code in the second project Secondapp

//

Viewcontroller.m

Secondapp

//

Created by Luorende on 16/8/26.

COPYRIGHT©2016 year Luorende. All rights reserved.

//

#import "ViewController.h"

@interface Viewcontroller ()

@end

@implementation Viewcontroller

-(void) Viewdidload {

[Super Viewdidload];

Do no additional setup after loading the view, typically from a nib.

UIButton * button = [UIButton buttonwithtype:uibuttontypecustom];

Button.frame = CGRectMake (100, 100, 200, 100);

Button.backgroundcolor = [Uicolor Darkgraycolor];

[Button settitle:@ "Secondapp, jump to another app" Forstate:uicontrolstatenormal];

Button.titleLabel.font = [Uifont systemfontofsize:20];

[Button addtarget:self action: @selector (Clickbutton:) forcontrolevents:uicontroleventtouchupinside];

[Self.view Addsubview:button];

}

-(void) Clickbutton: (UIButton *) button{

NSLog (@ "executed click event");

NSString * urlstr = @ "Firstapp://xxxxx";

Nsurl * url = [Nsurl urlwithstring:urlstr];

if ([[UIApplication Sharedapplication]canopenurl:url]) {

[[UIApplication sharedapplication] openurl:url];

}else{

NSLog (@ "Application not Installed");

Program did not successfully jump, we can also make a hint

Uialertview *alertview = [[Uialertview alloc]initwithtitle:@ application not installed ' message:@ ' to determine download <xxxx> application.] "Delegate:self cancelbuttontitle:@" Cancel "otherbuttontitles:@" OK ", nil];

Alertview.alertviewstyle = Uialertviewstyledefault;

[Alertview show];

}

Note: Another explanation

For example: when each jump to each other to set the URL and whitelist, if the Firstapp does not set the URL types (oneself register your own URL)

The implementation of the function is: Firstapp can jump to Secondapp, but Secondapp can't jump over

Of course, both sides only set the Lsapplicationqueriesschemes item is not OK, will prompt the application is not installed (whitelist)

Simply put, there is a need to set the URL

Set up their own words, that is, there is already a URL, others do not register, use the Set white list can also jump

Summary: Who wants to jump, who will set who is the white list. White list to be consistent with the domain name URL that jumps to the app settings. The URL of the Code section should also be preceded by the domain name URL

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.