到了2017.1.1,所有提交的app不允許使用 NSAllowsArbitraryLoads = Yes 來繞過ATS的限制,你必須設(shè)置為NO。

Screen Shot 2016-12-20 at 8.50.08 PM.png
如果你的app有著異常復(fù)雜的業(yè)務(wù)邏輯,手動排查找出所有的HTTP請求是非常費(fèi)時費(fèi)力的。
于是ATS自動化呼之欲出了。
下面記載了一些ATS自動化遇到的一些問題
定義問題
功能驗(yàn)證時能直接體驗(yàn)到功能的可用與否(或是網(wǎng)頁打不開、頭像拉取失?。K砸环N可取的方案就是打開ATS開關(guān),功能驗(yàn)證的測試同學(xué)們測試用例時輔助發(fā)現(xiàn)ATS問題。
但自動化怎么定義問題?
App日志
如果開發(fā)們在做HTTP請求時的completion回調(diào)里打印了error,那我們還是非常方便的從日志log提取問題的。(NSLog會直接打到控制臺)。但如果開發(fā)沒有打印error,那這部分問題就無法發(fā)現(xiàn)了

Screen Shot 2016-12-20 at 8.56.44 PM.png
Dec 20 20:57:50 TKMB161106H9 TestATS[3193] <Notice>: Request failed: Error Domain=NSURLErrorDomain Code=-1022 "The resource could not be loaded because the App Transport Security policy requires the use of a secure connection." UserInfo={NSUnderlyingError=0x170058ed0 {Error Domain=kCFErrorDomainCFNetwork Code=-1022 "(null)"}, NSErrorFailingURLStringKey=http://www.baidu.com/, NSErrorFailingURLKey=http://www.baidu.com/, NSLocalizedDescription=The resource could not be loaded because the App Transport Security policy requires the use of a secure connection.}
系統(tǒng)日志
當(dāng)然系統(tǒng)還是能覺察到HTTP請求的
Dec 20 20:31:46 TKMB161106H9 TestATS(CFNetwork)[3160] <Notice>: App Transport Security has blocked a cleartext HTTP (http://) resource load since it is insecure. Temporary exceptions can be configured via your app's Info.plist file.
Dec 20 20:31:46 TKMB161106H9 TestATS(CoreFoundation)[3160] <Debug>: Bundle: CFBundle 0x100410840 </System/Library/Frameworks/CFNetwork.framework> (framework, loaded), key: Err-1022, value: The resource could not be loaded because the App Transport Security policy requires the use of a secure connection., table: Localizable, localizationName: (null), result: The resource could not be loaded because the App Transport Security policy requires the use of a secure connection.
但遺憾的是:
- 這些log并不能看到請求的URL
- App啟動后如果系統(tǒng)發(fā)現(xiàn)HTTP請求,那只會打印一次第一條log(即...has blocked a cleartest...)
- 而第二條(即The resource could not...)只會在App安裝后第一次啟動發(fā)生HTTP請求時打出,以后再也不出現(xiàn)了
換句話說,系統(tǒng)在一個進(jìn)程里面發(fā)現(xiàn)第一個HTTP請求后會打印log1,之后都不會打印log1(除非強(qiáng)殺進(jìn)程重新啟動app,當(dāng)然這是另外一個進(jìn)程了)。打印log2,同時標(biāo)記對應(yīng)App,被標(biāo)記的App不會再打印log2。
怎么辦
結(jié)合代碼搜索,和App日志,我們能發(fā)現(xiàn)大部分的問題。當(dāng)然,剩下的那部分,我也暫時想不到辦法了。有高人有大法望留言告知我。