浏览器打开应用指定的界面-b

iOS中提供了两种在浏览器中打开APP的方法: Smart App Banner 和schema协议,这里介绍schema

在实际开发中我们可能会在浏览器中唤醒我们自己的app,就像手机QQ唤醒快报一样,如图:点击的时候直接打开快报客户端,并且跳转到制定的界面

这里写图片描述

这里写图片描述

而这个才是快报客户端的首页

这里写图片描述

1.在info.plist中注册URL协议(增加箭头的字段,item1的值就是我们的协议,类似http协议,可以用[协议名://]启动该app,可以自己在后面拼接参数)

这里写图片描述

2.访问自定义URL(在APPDelegate中实现方法)

//iOS9之前用这个
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
    if(!url){
        return NO;
    }
    //获取接受到的字符串连接,可以根据参数在这里进行跳转
    NSLog(@"%@",[url absoluteString]);
    return YES;
}

//iOS9系统推荐用这个
-(BOOL)application:(UIApplication*)app openURL:(NSURL*)url options:(NSDictionary<NSString *,id>*)options
{
    if(!url){
        return NO;
    }
    //获取接受到的字符串连接,可以根据参数在这里进行跳转
    NSLog(@"%@",[url absoluteString]);
    return YES;
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22

3.浏览器中输入[协议名://参数]便可访问–>回车

这里写图片描述

这里写图片描述

原文地址:https://www.cnblogs.com/isItOk/p/5791648.html