iOS之在自己的app里面如何打开其他app

1、想要打开其他APP,需要知道目标APP的URL Scheme,然后调用UIApplication的 openURL:方法即可打开

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

2、 配置Scheme白名单
2.1、在iOS 9下涉及到平台客户端跳转,系统会自动到项目info.plist下检测是否设置平台Scheme。对于需要配置的平台,如果没有配置,就无法正常跳转平台客户端。因此要支持客户端的分享和授权等,需要配置Scheme名单
2.2、具体方法:
2.2.1、在项目的info.plist中添加一LSApplicationQueriesSchemes,类型为Array。
2.2.2、然后给它添加一个需要支持的项目,类型为字符串类型;
2.3、想要获取具体的各个平台的白名单,看第三方平台就可以,例如:
sharesdk分享 iOS9适配文档地址
友盟分享 iOS9适配地址
2.4、info.plist示例图
这里写图片描述
3、常用URL Scheme
常用URL scheme查询 http://handleopenurl.com/scheme
QQ: mqq://
微信: weixin://
新浪微博: weibo:// (sinaweibo://)
腾讯微博: tencentweibo://
4、示例代码

- (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://"]];
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值