iOS相关技术实现

唤醒APP

2018-07-17  本文已影响84人  小凡凡520
URL Scheme

iOS在实际使用中,腾讯系的微信,QQ明确禁止使用,iOS9以后Safari不再支持通过js,iframe等来触发scheme跳转,并且还加入了确认机制,使得通过js超时机制来自动唤醒APP的方式基本不可用

Android intent
<!-- 唤醒APP并跳转至指定的path页面 -->
<a href="intent://<role>/<path>#Intent;scheme=<scheme>;package=com. domain;end"">打开APP</a>
Safari内置APP广告条
<meta"apple-itunes-app"content"app-id=myAppStoreID, affiliate-data=myAffiliateData, app-argument=myURL"
Android Chrome内置APP安装提示
iOS Universal Links

在2015年的WWDC大会上,Apple推出了iOS 9的一个功能:Universal Links通用链接。如果你的App支持Universal Links,那就可以访问HTTP/HTTPS链接直接唤起APP进入具体页面,不需要其他额外判断;如果未安装App,访问此通用链接时,可以一个自定义网页。

1、新建一个json文件 必须命名为 ‘apple-app-site-association’,不带后缀,内容如下

    {
      "applinks": {
          "apps": [],
          "details": [
                 {
                    "appID": "9JA89QQLNQ.com.apple.wwdc", 
                    "paths": [ "/wwdc/news/", "/videos/wwdc/2015/*"]
                },
              {
                  "appID": "ABCD1234.com.apple.wwdc", 
                  "paths": [ "*" ]
              }
          ]
    }
}

// appID = teamId.yourapp's bundle identifier
// paths = APP支持的路径列表,只有这些指定的路径的链接,才能被APP所处理,大小写敏感

2、将以上的json文件上传到网站的 .well-known 目录下
3、激活Xcode工程中的Associated Domains能力,在其中的Domains中填入你想支持的域名(必须以applinks:为前缀

 例如: applinks:www.domain.com

4、登陆开发者中心,查看Associated Domains状态
5、代码实现

func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([Any]?) -> Void) -> Bool {
    if userActivity.activityType == NSUserActivityTypeBrowsingWeb {
        if let webpageURL = userActivity.webpageURL {
            let host = webpageURL.host
            if host == "****" {
                //进行我们需要的处理
            } else {
                UIApplication.shared.openURL(webpageURL
            }
        }
    }
    return true
}
Android App Links
上一篇下一篇

猜你喜欢

热点阅读