一个程序若要跳到另一个程序。需要在目标程序的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打头即可

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

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

    两个APP之间的跳转是通过[[UIApplication sharedApplication] openURL:url]这种方式来实现的. 1.首先设置第一个APP的url地址 2.接着设置第二个AP ...

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

    app间的跳转 一:在第一个app首先要做下面这些操作: 1.在info.plist文件中的Information Property List下添加一项:URL types. 2.点开URL type ...

  3. 两个App之间的跳转 并传值

    两个App之间的传值最主要的是方法是 Intent intent = getPackageManager().getLaunchIntentForPackage("com.example.a ...

  4. iOS 两个App之间调起通信

    前言 假设需求是这样的:由一个app1跳转到app2之后,app2完成某项任务之后,怎么把app2的完成信息传到app1(自己的程序是app1),传的是什么类型的数据,怎么进行解析? 逻辑 本文章使用 ...

  5. iOS 两个页面之间的跳转

    -------->-------->-------->-------->-------->-------->-------->   以上完成页面one跳到页面 ...

  6. iOS APP之间到跳转,以及热门应用,手机自带到应用跳转

    应用之间的跳转 在第一个APP中,做如下操作:1.在info.plist文件中的"信息属性列表"下添加一项:"URL类型"; 2.点开"URL类型&q ...

  7. 两个APP之间怎么调用《IT蓝豹》

    两个app之间怎么调用?   (1):通过显示Intent 启动    首先:配置好B app 的action,即AndroidManifest.xml中声明 <intent-filter> ...

  8. 通过AIDL在两个APP之间Service通信

    一.项目介绍 [知识准备] ①Android Interface definition language(aidl,android接口定义语言),其目的实现跨进程的调用.进程是程序在os中执行的载体, ...

  9. iOS开发-应用之间的跳转及通信

    Update 2016-08-12: 在Github的Demo上增加Mac自定义Url Scheme,可以在Safari上输入特定协议头打开应用,并传递参数) 简介 我们接下来将要实现应用程序之间的跳 ...

随机推荐

  1. vim vi 及其相关插件的使用

    GIMP->linux下16位图查看工具 实用手册:130+ 提高开发效率的 vim 常用命令 http://www.cnblogs.com/lhb25/p/130-essential-vim- ...

  2. 安装CentOS

    1. 用UltraISO,将CentOS写入U盘,然后将两个CentOS iso文件也拷贝到u盘中,由于u盘FAT32的限制,需要调整第一个iso文件的尺寸,剪切到4GB以内即可拷贝进u盘 2. 用u ...

  3. 从个人的角度谈谈本次GNTC大会的收获

    GNTC资料:from sdnlab 从个人的角度谈谈本次大会的收获 从本次大会的主题演讲来看,目前SDN.NFV的最前沿已经不再像五年前持观望态度以及探讨,各大运营商.各大厂商已经将SDN.NFV具 ...

  4. tomcat bug之部署应用的时候经常会发上startup failed due to previous errors

    在tomcat上部署应用的时候经常会发上startup failed due to previous errors错误.这个错误产生以后经常会让人摸不到头脑.以下是几点查找经验: 1.web.xml文 ...

  5. centos7 安装mysql5.7及配置

    一.Mysql 各个版本区别:1.MySQL Community Server 社区版本,开源免费,但不提供官方技术支持.2.MySQL Enterprise Edition 企业版本,需付费,可以试 ...

  6. 【转】C# HttpWebRequest\HttpWebResponse\WebClient发送请求解析json数据

    http://blog.csdn.net/kingcruel/article/details/44036871 版权声明:本文为博主原创文章,未经博主允许不得转载. ================= ...

  7. Java高级之内存模型分析

    博客出自:http://blog.csdn.net/liuxian13183,转载注明出处! All Rights Reserved ! 下文是博主感悟,请带着怀疑性的态度阅读! 需要了解基本变量所占 ...

  8. JVM GC (一)

    1. 先来说GC工作在哪块区域呢? 程序计数器,虚拟机栈(也就平时所说的栈), 本地方法栈这三区域随着线程而生,随着线程而灭,出栈入栈的操作,在栈中分配配的多少内存都具 有确定性,在这几个区域就不用考 ...

  9. Qt通过QToolTip显示浮动信息

    QToolTip类的应用十分简单,其QToolTip类中全都是静态方法,如果要显示浮动信息的话使用该函数即可: void QToolTip::showText ( const QPoint & ...

  10. ASP.NET MVC3更新出错:ObjectStateManager中已存在具有同一键的对象

    程序代码: [HttpPost] public ActionResult Edit(Person person) { if (ModelState.IsValid) { Person oldperso ...