IOS 10适配https 包含对于一些http的一些兼容配置

iOS10 从2017年1月1日起苹果提出所有新提交的App默认不允许使用NSAllowsArbitraryLoads来绕过ATS的限制,也就是说强制我们用HTTPS,如果不这样的话提交App可能会被拒绝。或者你加入说明限制可能会过!

 

 一.关于证书

通常你们公司会有两种情况:

1.我们公司没钱,自己想办法搞证书,哈哈哈。是不是很苦逼,然后你就自行进行配置:参考其他博客 (这些还不知道苹果支持不支持,待定的)

2.你们公司很有钱,喔,大公司,like ours company;我们公司买的天威诚信的证书(普及一下,https证书加密,分为双向认证和单向认证,单向认证的都不需要客户端做什么)

首先我们去天威购买了证书。实际前端上什么都不需要处理。最多了你就在AFNet里边加安全性需要证书验证就行。

        _sharedClient = [MssageAFNetRequest manager];

        AFSecurityPolicy *securityPolicy = [AFSecurityPolicy policyWithPinningMode:AFSSLPinningModeCertificate];

        securityPolicy.allowInvalidCertificates = NO;

        securityPolicy.validatesDomainName = YES;

        _sharedClient.securityPolicy = securityPolicy;

这时候你需要删除plist里边的安全设置的info.plist文件中添加AppTransportSecuritySettings字典,将NSAllowsArbitraryLoads设置为YES来禁用ATS。这个选项,大家都是过来人以前都是这样做的。

然后 ---------------------------分割线以下--------------------------

需要配置plist对兼容一些第三方啊或者不是https的请求域名加入http配置白名单,请求的网络图片是HTTP:

操作:

    1)在项目info.plist中添加一个Key:App Transport Security Settings,类型为

       Dictionary;

    2)在其内添加一个Key: Exception Domains,类型为Dictionary;

    3)在Exception Domains内添加要支持的域,其中域作为Key,类型为Dictionary;

    4)每个域下面需要设置3个属性:类型为Boolean; 

       NSIncludesSubdomains  YES

       NSExceptionRequiresForwardSecrecy  NO

       NSExceptionAllowsInsecureHTTPLoads  YES

       

   注意:每个需添加的域都需要设置此三个属性。如果请求的网络图片是HTTP,也是需要设置的图片的域。

 

 二.关于第三方配置


若果工程中涉及到第三方比如:友盟分享(集成的第三方分享),聊天的容云,bugly等。

你都需要重新配置或者看第三方的更新文档。比如微博的需要加入白名单的域名:

<key>sina.com.cn</key> <dict> <key>NSIncludesSubdomains</key> <true/> <key>NSThirdPartyExceptionAllowsInsecureHTTPLoads</key> <true/> <key>NSThirdPartyExceptionRequiresForwardSecrecy</key> <false/> </dict> <key>sinaimg.cn</key> <dict> <key>NSIncludesSubdomains</key> <true/> <key>NSThirdPartyExceptionAllowsInsecureHTTPLoads</key> <true/> <key>NSThirdPartyExceptionRequiresForwardSecrecy</key> <false/> </dict> <key>sinajs.cn</key> <dict> <key>NSIncludesSubdomains</key> <true/> <key>NSThirdPartyExceptionAllowsInsecureHTTPLoads</key> <true/> <key>NSThirdPartyExceptionRequiresForwardSecrecy</key> <false/> </dict> <key>sina.cn</key> <dict> <key>NSExceptionMinimumTLSVersion</key> <string>TLSv1.0</string> <key>NSIncludesSubdomains</key> <true/> <key>NSThirdPartyExceptionRequiresForwardSecrecy</key> <false/> </dict> <key>weibo.cn</key> <dict> <!-- 适配iOS10 --> <key>NSExceptionMinimumTLSVersion</key> <string>TLSv1.0</string> <key>NSIncludesSubdomains</key> <true/> <key>NSThirdPartyExceptionRequiresForwardSecrecy</key> <false/> </dict> <key>weibo.com</key> <dict> <key>NSExceptionMinimumTLSVersion</key> <string>TLSv1.0</string> <key>NSIncludesSubdomains</key> <true/> <key>NSThirdPartyExceptionAllowsInsecureHTTPLoads</key> <true/> <key>NSThirdPartyExceptionRequiresForwardSecrecy</key> <false/>

 

 

谁让新浪的域名很多呢!其他的要自行配置...

posted @ 2016-12-16 11:46  PeterWolf  阅读(962)  评论(0编辑  收藏  举报