0. 想要打开其他APP,需要知道目标APP的URL Scheme,然后调用UIApplication的 openURL:方法即可打开
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"weixin://"]];
1. 配置Scheme白名单
在iOS 9下涉及到平台客户端跳转,系统会自动到项目info.plist下检测是否设置平台Scheme。对于需要配置的平台,如果没有配置,就无法正常跳转平台客户端。因此要支持客户端的分享和授权等,需要配置Scheme名单
具体方法:
在项目的info.plist中添加一LSApplicationQueriesSchemes,类型为Array。
然后给它添加一个需要支持的项目,类型为字符串类型;
想要获取具体的各个平台的白名单,看第三方平台就可以,例如:
sharesdk分享 iOS9适配文档地址http://wiki.mob.com/ios9-%E5%AF%B9sharesdk%E7%9A%84%E5%BD%B1%E5%93%8D%EF%BC%88%E9%80%82%E9%85%8Dios-9%E5%BF%85%E8%AF%BB%EF%BC%89/
友盟分享 iOS9适配地址
http://dev.umeng.com/social/ios/ios9info.plist示例图
2. 常用URL Scheme
- 常用URL scheme查询 http://handleopenurl.com/scheme
QQ: mqq://
微信: weixin://
新浪微博: weibo:// (sinaweibo://)
腾讯微博: tencentweibo://
3. 示例代码
- (void)viewDidLoad {
[super viewDidLoad];
[self addweixinbutton];
[self addqqbutton];
}
- (void)addqqbutton
{
UIButton *button = [[UIButton alloc] init];
[button setTitle:@"打开QQ" forState:UIControlStateNormal];
[button setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
[self.view addSubview:button];
button.frame = CGRectMake(100, 250, 100, 100);
[button addTarget:self action:@selector(openQQ) forControlEvents:UIControlEventTouchUpInside];
}
- (void)addweixinbutton
{
UIButton *button = [[UIButton alloc] init];
[button setTitle:@"打开微信" forState:UIControlStateNormal];
[button setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
[self.view addSubview:button];
button.frame = CGRectMake(100, 100, 100, 100);
[button addTarget:self action:@selector(openWeixin) forControlEvents:UIControlEventTouchUpInside];
}
/**
* 需要在info里面添加 LSApplicationQueriesSchemes字段
*/
- (void)openQQ
{
NSURL *url = [NSURL URLWithString:@"mqq://"];
if([[UIApplication sharedApplication] canOpenURL:url]){
[[UIApplication sharedApplication] openURL:url];
} else {
UIAlertView*ale=[[UIAlertView alloc] initWithTitle:@"提示" message:@"您没有安装手机QQ,请安装手机QQ后重试,或用PC进行操作。" delegate:self cancelButtonTitle:nil otherButtonTitles:@"确定", nil];
[ale show];
}
}
/**
* 打开微信 , 没有配置
*/
- (void)openWeixin
{
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"weixin://"]];
}
- iOS技术开发交流QQ群: 579572313