本文为大家分享了ios实现app间跳转功能的具体代码,供大家参考,具体内容如下
我们通过系统的openurl方法,可以从当前的app跳转到其他任意app去,包括系统自带的、以及我们开发的app。
本文模拟a app跳转到 b app
a app代码:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
// a app
// viewcontroller.m
// 程序跳转
//
// created by hhg on 15/10/23.
// copyright (c) 2015年 hhg. all rights reserved.
//
#import "viewcontroller.h"
@interface viewcontroller ()
@end
@implementation viewcontroller
- ( void )viewdidload {
[super viewdidload];
}
- ( void )touchesbegan:(nsset *)touches withevent:(uievent *)event {
// 为我们的程序设置一个唯一的标识,那么其他软件就可以使用openurl方法通过唯一标识来打开我们的程序
[[uiapplication sharedapplication]openurl:[nsurl urlwithstring:@ "zapp:" ]];
}
- ( void )didreceivememorywarning {
[super didreceivememorywarning];
}
@end
|
b app代码:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
// b app
// appdelegate.m
// myapp
//
// created by hhg on 15/10/23.
// copyright (c) 2015年 hhg. all rights reserved.
//
#import "appdelegate.h"
@interface appdelegate ()
@end
@implementation appdelegate
- ( bool )application:(uiapplication *)application didfinishlaunchingwithoptions:(nsdictionary *)launchoptions {
return yes;
}
// 当其他程序通过openurl打开该程序的时候,会触发这个方法
// url ,就是其他程序打开时候的url
- ( bool )application:(uiapplication *)application openurl:(nsurl *)url sourceapplication:(nsstring *)sourceapplication annotation:(id)annotation {
uialertview *alertview = [[uialertview alloc]initwithtitle:@ "提示" message:@ "跳转成功!" delegate:nil cancelbuttontitle:@ "确定" otherbuttontitles: nil];
[alertview show];
return yes;
}
- ( void )applicationwillresignactive:(uiapplication *)application {
}
- ( void )applicationdidenterbackground:(uiapplication *)application {
}
- ( void )applicationwillenterforeground:(uiapplication *)application {
}
- ( void )applicationdidbecomeactive:(uiapplication *)application {
}
- ( void )applicationwillterminate:(uiapplication *)application {
}
@end
|
b app 在info.plist 文件里面需要设置:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
<?xml version= "1.0" encoding= "utf-8" ?>
<!doctype plist public "-//apple//dtd plist 1.0//en" "http://www.apple.com/dtds/propertylist-1.0.dtd" >
<plist version= "1.0" >
<array>
<dict>
<key>cfbundleurlname</key>
<string></string>
<key>cfbundleurlschemes</key>
<array>
<string>zapp</string>
</array>
</dict>
</array>
</plist>
|
如图:
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持服务器之家。
原文链接:https://blog.csdn.net/csdn_hhg/article/details/80446105