iOS9 URL Schme 白名单

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

 

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

enter image description here

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

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

  

白名单上限是50个:chrome

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

“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 Appapi

 

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

enter image description here

苹果为何要这么作?session

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

这也许就是缘由。iphone

本项目中给出了一个演示用的 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>

  

参考连接 。

相关文章
相关标签/搜索