0. 想要打開其他APP,需要知道目標(biāo)APP的URL Scheme,然后調(diào)用UIApplication的 openURL:方法即可打開
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"weixin://"]];
1. 配置Scheme白名單
在iOS 9下涉及到平臺(tái)客戶端跳轉(zhuǎn)焚辅,系統(tǒng)會(huì)自動(dòng)到項(xiàng)目info.plist下檢測(cè)是否設(shè)置平臺(tái)Scheme。對(duì)于需要配置的平臺(tái)确沸,如果沒有配置,就無法正常跳轉(zhuǎn)平臺(tái)客戶端甲献。因此要支持客戶端的分享和授權(quán)等讯检,需要配置Scheme名單
具體方法:
在項(xiàng)目的info.plist中添加一LSApplicationQueriesSchemes整袁,類型為Array。
然后給它添加一個(gè)需要支持的項(xiàng)目志膀,類型為字符串類型熙宇;
想要獲取具體的各個(gè)平臺(tái)的白名單,看第三方平臺(tái)就可以,例如:
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:@"您沒有安裝手機(jī)QQ,請(qǐng)安裝手機(jī)QQ后重試溉浙,或用PC進(jìn)行操作烫止。" delegate:self cancelButtonTitle:nil otherButtonTitles:@"確定", nil];
[ale show];
}
}
/**
* 打開微信 , 沒有配置
*/
- (void)openWeixin
{
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"weixin://"]];
}
- iOS技術(shù)開發(fā)交流QQ群: 579572313