iOS Url Scheme实践-2020-05-29

2020-05-29  本文已影响0人  勇往直前888

简介

通用链接比较麻烦,还要放配置文件到网站上面,简直让人深恶痛绝。Url Scheme方式相对简单点。

添加URL Scheme

企业微信截图_377cc0b2-f0ca-4099-8299-6807e284fa33.png

被打开后的处理

被打开之后,外部输入的url是可以接受到的。可以在AppDelegate.m中的application:openURL:options:方法中处理。这里只是展示一下url的内容

- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options {
    
    // 被外部浏览器打开,这里展示整个的url
    NSString *test = url.absoluteString;
    
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"URL内容" message:test preferredStyle:UIAlertControllerStyleAlert];
    
    [alert addAction:[UIAlertAction actionWithTitle:@"知道了" style:UIAlertActionStyleDefault handler:nil]];
    [self.window.rootViewController presentViewController:alert animated:YES completion:nil];
    
    return YES;
}

测试1:Safari启动

在Safari浏览器中输入:haieruplus://host/path?param1=one然后回车,就可以看到APP被打开:

企业微信截图_d5a1a21d-cc29-4def-9859-8f585e45e74f.png

测试2:在其他APP中启动

其他APP只要用openURL方法就可以唤起,只要保证schemehaieruplus://就可以。

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"haieruplus://www.kjtpay.com?test=one"]];

问题1:可能会被支付宝禁止

写了一个scheme跳转,通过Safari浏览器,通过其他app,通过H5页面,都能够正常唤起APP。
但是,APP通过openURL拉起支付宝,支付宝再跳转H5页面,在H5页面中,想再唤起APP,就没有反应了。

参考文章

iOS中使用URLScheme进行App跳转

上一篇 下一篇

猜你喜欢

热点阅读