zoukankan      html  css  js  c++  java
  • iOS9 URL Schme 白名单

    原文地址: https://github.com/ChenYilong/iOS9AdaptationTips

    WWDC 2015 Session 703: "Privacy and Your App ( 时间在30:18左右)关于 URL scheme 的介绍,指出:

    enter image description here

    也就是说:在iOS9中,如果使用 canOpenURL: 方法,该方法所涉及到的 URL scheme 必须在"Info.plist"中将它们列为白名单,否则不能使用。key叫做LSApplicationQueriesSchemes ,键值内容是

    <key>LSApplicationQueriesSchemes</key>
    <array>
     <string>urlscheme</string>
     <string>urlscheme2</string>
     <string>urlscheme3</string>
     <string>urlscheme4</string>
    </array> 
    

      

    白名单上限是50个:

    WWDC 2015 Session 703: "Privacy and Your App )有说明:

    “So for apps that are linked before iOS 9 and are running on iOS 9, they will be given 50 distinct URL schemes.” -- WWDC 2015 session 703 Privacy and Your App

    iOS9中 openURL: 方法没有什么实质性的变化,仅仅多了一个确认动作:

    enter image description here

    苹果为什么要这么做?

    在 iOS9 之前,你可以使用 canOpenURL: 监测用户手机里到底装没装微信,装没装微博。但是也有一些别有用心的 App ,这些 App 有一张常用 App 的 URL scheme,然后他们会多次调用canOpenURL: 遍历该表,来监测用户手机都装了什么 App ,比如这个用户装了叫“大姨妈”的App,你就可以知道这个用户是女性,你就可以只推给这个用户女性用品的广告。这是侵犯用户隐私的行为。

    这也许就是原因。

    本项目中给出了一个演示用的 Demo ,仓库的文件夹叫“Demo3_iOS9URLScheme适配_引入白名单概念”,Demo引用自LSApplicationQueriesSchemes-Working-Example

    Demo结构如下:

    enter image description here

    主要演示的情景是这样的:

    假设有两个App: weixin(微信) and 我的App. 我的App 想监测 weixin(微信) 是否被安装了. "weixin(微信)" 在 info.plist 中定义了 URL scheme :

    <key>CFBundleURLTypes</key>
    <array>
        <dict>
            <key>CFBundleURLSchemes</key>
            <array>
                <string>weixin</string>
            </array>
        </dict>
    </array>
    

      

    我的App 想监测 weixin(微信) 是否被安装了 :

    [[UIApplication sharedApplication]
                        canOpenURL:[NSURL URLWithString:@"weixin(微信)://"]];
    

      

    即使你安装了微信,在iOS9中,这有可能会返回NO:

    因为你需要将 "weixin(微信)" 添加到 “我的App” 的 info.plist 文件中:

    <key>LSApplicationQueriesSchemes</key>
    <array>
        <string>weixin</string>
    </array>
    

      

    (以上只是为了演示,实际开发中,你不仅需要添加“weixin”还需要“wechat”这两个。具体下文给出表格)

    另外,推荐一篇博文,其中最关键的是以下部分:

    If you call the “canOpenURL” method on a URL that is not in your whitelist, it will return “NO”, even if there is an app installed that has registered to handle this scheme. A “This app is not allowed to query for scheme xxx” syslog entry will appear.

    常见 URL Scheme

    如果想一次性集成最常用的微信、新浪微博、QQ、支付宝四者的白名单,则配置如下:

     <key>LSApplicationQueriesSchemes</key>
    <array>
        <!-- 微信 URL Scheme 白名单-->
        <string>wechat</string>
        <string>weixin</string>
    
        <!-- 新浪微博 URL Scheme 白名单-->
        <string>sinaweibohd</string>
        <string>sinaweibo</string>
        <string>sinaweibosso</string>
        <string>weibosdk</string>
        <string>weibosdk2.5</string>
    
        <!-- QQ、Qzone URL Scheme 白名单-->
        <string>mqqapi</string>
        <string>mqq</string>
        <string>mqqOpensdkSSoLogin</string>
        <string>mqqconnect</string>
        <string>mqqopensdkdataline</string>
        <string>mqqopensdkgrouptribeshare</string>
        <string>mqqopensdkfriend</string>
        <string>mqqopensdkapi</string>
        <string>mqqopensdkapiV2</string>
        <string>mqqopensdkapiV3</string>
        <string>mqzoneopensdk</string>
        <string>wtloginmqq</string>
        <string>wtloginmqq2</string>
        <string>mqqwpa</string>
        <string>mqzone</string>
        <string>mqzonev2</string>
        <string>mqzoneshare</string>
        <string>wtloginqzone</string>
        <string>mqzonewx</string>
        <string>mqzoneopensdkapiV2</string>
        <string>mqzoneopensdkapi19</string>
        <string>mqzoneopensdkapi</string>
        <string>mqzoneopensdk</string>
    
        <!-- 支付宝  URL Scheme 白名单-->
        <string>alipay</string>
        <string>alipayshare</string>
    
    </array>
    

      

    plist 文件看起来会是这样的:

    enter image description here

    其他平台可在下面的列表中查询: 各平台OpenURL白名单说明

    平台名称URL Schem补充说明
    微信 wechat, weixin  
    支付宝 alipay, alipayshare  
    QQ mqqOpensdkSSoLogin, mqqopensdkapiV2, mqqopensdkapiV3, wtloginmqq2, mqq, mqqapi  
    QZONE mqzoneopensdk, mqzoneopensdkapi, mqzoneopensdkapi19, mqzoneopensdkapiV2, mqqOpensdkSSoLogin, mqqopensdkapiV2, mqqopensdkapiV3, wtloginmqq2, mqqapi, mqqwpa, mqzone, mqq [注:若同时使用QQ和QZONE,则直接添加本格即可]
    新浪微博 sinaweibo, sinaweibohd, sinaweibosso, sinaweibohdsso, weibosdk, weibosdk2.5 [后两个若导入新浪SDK则需要]
    豆瓣 无需配置  
    开心网 无需配置  
    易信 yixin, yixinopenapi  
    Google+ googlechrome, googlechrome-x-callback, hasgplus4, com.google.gppconsent, com.google.gppconsent.2.2.0, com.google.gppconsent.2.3.0, com.google.gppconsent.2.4.0, com.google.gppconsent.2.4.1  
    人人网 renrenapi, renrenios, renreniphone, renren,  
    Facebook 见下文  
    Twitter 无需配置  
    Pocket pocket-oauth-v1  
    Pinterest pinit  
    Instagram instagram  
    WhatsApp whatsapp  
    Line line  
    KakaoTalk kakaolink  
    KaokaoStory storylink  
    LinkedIn 无需配置  
    Tumblr 无需配置  
    非平台类 无需配置 ( 如短信,复制,邮件等)

    另外, Facebook 的URL Scheme白名单需要注意:

    如果 SDK 版本低于 4.5 应补充

    <key>LSApplicationQueriesSchemes</key>
    <array>
        <string>fbapi</string>
        <string>fbapi20130214</string>
        <string>fbapi20130410</string>
        <string>fbapi20130702</string>
        <string>fbapi20131010</string>
        <string>fbapi20131219</string>    
        <string>fbapi20140410</string>
        <string>fbapi20140116</string>
        <string>fbapi20150313</string>
        <string>fbapi20150629</string>
        <string>fbauth</string>
        <string>fbauth2</string>
        <string>fb-messenger-api20140430</string>
    </array>
    

      

    如果使用 FBSDKMessengerShareKit,还要加上

    <string>fb-messenger-platform-20150128</string>
    <string>fb-messenger-platform-20150218</string>
    <string>fb-messenger-platform-20150305</string>
    

      

    如果使用SDK版本高于4.6,则只需要加上

    <key>LSApplicationQueriesSchemes</key>
    <array>
            <string>fbapi</string>
            <string>fb-messenger-api</string>
            <string>fbauth2</string>
            <string>fbshareextension</string>
    </array>
    

      

    参考链接 。

  • 相关阅读:
    angular 复选框回选
    $parse
    AngularJS 指令的 Scope (作用域)
    文献解读 (1)
    献给初学者:常用的细胞凋亡检测方法
    KofamKOALA
    Dfam.h5.gz下载
    Augustus-3.3.3安装
    bamtools 2.5.1安装
    R语言从原点开始作图
  • 原文地址:https://www.cnblogs.com/FranZhou/p/5190627.html
Copyright © 2011-2022 走看看