iOS 之(两个APP之间的跳转)

一个程序若要跳到另一个程序。需要在目标程序的plist文件里面修改:

打开info.plist,添加一项URL types

展开URL types,再展开Item0,将Item0下的URL identifier修改为URL Scheme

展开URL Scheme,将Item0的内容修改为 SecondApp(此为跳转的key)

话不多说,下面开始讲解步骤:

首先创建两个工程,第一个 FirstAPP , 第二个 SecondAPP

第一个 First APP 的 info.plist 需要设置 key(url) 与 白名单

接下来我们再对第二个 SecondAPP 工程来做相应的处理

将这两个工程设置好了之后,接下来上代码

  第一个 FirstApp工程

//

//  ViewController.m

//  FirstAPP

//

//  Created by luorende on 16/8/25.

//  Copyright © 2016年 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:@"跳转到SecondApp" forState:UIControlStateNormal];

button.titleLabel.font = [UIFont systemFontOfSize:20];

[button addTarget:self action:@selector(clickButton:) forControlEvents:UIControlEventTouchUpInside];

[self.view addSubview:button];

}

//跳转到SecondApp

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

NSLog(@"执行了点击事件");

//之前配置的白名单,就是需要跳转对方App的key,即对方设置的url

NSString * UrlStr = @"SecondApp://xxxxx";

NSURL * url = [NSURL URLWithString:UrlStr];

// 在这里可以先做个判断

if ([[UIApplication sharedApplication]canOpenURL:url]) {

[[UIApplication sharedApplication] openURL:url];

}else{

NSLog(@"应用程序未安装");

}

}

//跳转到AppStore

-(void)abc{

[[UIApplication sharedApplication]openURL:[NSURL URLWithString:@""]];

[[UIApplication sharedApplication]openURL:[NSURL URLWithString:@""]];

}

  第二个工程 SecondAPP 里的代码

//

//  ViewController.m

//  SecondAPP

//

//  Created by luorende on 16/8/26.

//  Copyright © 2016年 luorende. All rights reserved.

//

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {

[super viewDidLoad];

// Do any 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,跳转到另一个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(@"执行了点击事件");

NSString * UrlStr = @"FirstAPP://xxxxx";

NSURL * url = [NSURL URLWithString:UrlStr];

if ([[UIApplication sharedApplication]canOpenURL:url]) {

[[UIApplication sharedApplication] openURL:url];

}else{

NSLog(@"应用程序未安装");

// 程序未成功跳转,我们还可以做一个提示

UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"应用程序未安装"message:@"确定下载<xxxx>应用吗?" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定",nil];

alertView.alertViewStyle = UIAlertViewStyleDefault;

[alertView show];

}

  注: 另外说明一下

例如:相互跳转的时候双方都要设置URL与白名单 ,若是 FirstAPP 不设置URL types 项(自己注册自己URL)

则实现的功能是:FirstAPP 可以跳转到 SecondAPP  ,但SecondAPP无法跳转过来

当然双方只设置 LSApplicationQueriesSchemes  项也是不行的,会提示应用程序未安装  (白名单)

简单说来 就是需要有一个要设置 URL

自己设置了的话,就是说已经有了URL,别人不注册, 使用设置白名单后也能跳转

总结:谁要跳,谁就要设置谁为白名单。  白名单要与跳到App设置的域名URL 要保持一致 另外代码部分的URL也要以域名URL打头即可

时间: 2024-08-01 04:06:38

iOS 之(两个APP之间的跳转)的相关文章

iOS中两个APP之间的跳转和通信

app间的跳转 一:在第一个app首先要做下面这些操作: 1.在info.plist文件中的Information Property List下添加一项:URL types. 2.点开URL types下的item 0,再点开item 0,将item 0下的URL identifier改为URL Schemes. 3.点开URL Schemes下的item 0,在它后面添加skipOne(skipOne为第一个app的跳转标识,这里根据你自己写的来) 二:在第二个app中,在需要跳转到第一个ap

两个App之间的跳转 并传值

两个App之间的传值最主要的是方法是 Intent intent = getPackageManager().getLaunchIntentForPackage("com.example.app2");其他的传值用Intent完成就行 与activity之间的传值类似 (还可以自定义activity的权限) APP1: package com.example.app1; import android.content.Intent; import android.support.v7.a

ios两个app之间跳转,传值的实现

两个APP之间的跳转是通过[[UIApplication sharedApplication] openURL:url]这种方式来实现的. 1.首先设置第一个APP的url地址 2.接着设置第二个APP的url地址 3.需要跳转的时候 NSString *urlString = [NSString stringWithFormat:@"AppJumpSecond://%@",textField.text]; [[UIApplication sharedApplication] open

app之间的跳转以及传参数

两个APP之间的跳转是通过[[UIApplication sharedApplication] openURL:url]这种方式来实现的. 1.首先设置第一个APP的url地址 2.接着设置第二个APP的url地址 3.需要跳转的时候 NSString *urlString = [NSString stringWithFormat:@"AppJumpSecond://%@",textField.text]; [[UIApplication sharedApplication] open

iOS开发拓展篇—应用之间的跳转和数据传递

iOS开发拓展篇—应用之间的跳转和数据传 说明:本文介绍app如何打开另一个app,并且传递数据. 一.简单说明 新建两个应用,分别为应用A和应用B. 实现要求:在appA的页面中点击对应的按钮,能够打开appB这个应用. 1.新建两个应用,分别为A和B.     2.设置应用B的url. 3.在应用A中编写打开app的代码 点击之后,会跳转到新的控制器. 注意:打开应用B的过程中,B有两种状态. 第一种状态:B并没有启动,那么会启动B.并调用下面的方法. 第二种状态:此时B已经启动了,但是在后

iOS开发拓展篇—应用之间的跳转和数据传

iOS开发拓展篇—应用之间的跳转和数据传 说明:本文介绍app如何打开另一个app,并且传递数据. 一.简单说明 新建两个应用,分别为应用A和应用B. 实现要求:在appA的页面中点击对应的按钮,能够打开appB这个应用. 1.新建两个应用,分别为A和B.     2.设置应用B的url. 3.在应用A中编写打开app的代码 点击之后,会跳转到新的控制器. 注意:打开应用B的过程中,B有两种状态. 第一种状态:B并没有启动,那么会启动B.并调用下面的方法. 第二种状态:此时B已经启动了,但是在后

iOS 判断两个日期之间的间隔

两个时间段,判断之间的相差,做一些时间范围限制使用 NSDateFormatter * dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setDateFormat:@"yyyyMMddHHmmss"]; NSDate* toDate     = [dateFormatter dateFromString:@"20140702142033"]; NSDate*  startDate    =

IOS两个应用之间的跳转

开发IOS项目的时候,有可能会遇到两个APP应用相互调用的需求,比如说:支付宝支付......等等. 下面来详细介绍实现的步骤: 1,添加URL Types项 a,打开项目中info.plist文件,在infomation property list项下面增加一项URL Typs 2,配置URL Scheme a,展开URL types,再展开Item1,将Item1下的URL identifier修改为URL Scheme b,展开URL Scheme,将Item1的内容修改为myapp (其

app之间的跳转,进入二级界面

功能实现:A跳到B并打开B中指定页面.http://blog.csdn.net/dollyyang/article/details/50325307 点击页面判断是否安装app并打开,否则跳转app store的方法 步骤: 1.首先创建两个项目(项目A,项目B),在项目B中的info.plist文件中添加URL Types,如下图所示:其中URL idenifier是项目B的bundle id ,URL Schemes 中添加一个命令前缀,我这里使用“projectB”,这个名字可以自己取,运