從 IOS9 起,新特征請求 App 拜訪收集要求,要采取 HTTPS 協定。然則能不克不及斷定開辟者能否許可 HTTP 的要求,如許就不會在提議要求時刻掉敗同時彈出以下信息:
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.
這個需求實際上是比來在弄 HTTPDNS 相干的一些器械,只能經由過程 HTTP 接口要求,然則願望能斷定運用能否許可了 HTTP 的拜訪,假如許可才開啟 HTTPDNS 相干的功效。
處理辦法比擬簡略,其實就是讀取 info.plist 看看 NSAppTransportSecurity 能否為 YES。
Objective-C 完成
- (BOOL)isHTTPEnable { if([[[UIDevice currentDevice] systemVersion] compare:@"9.0" options:NSNumericSearch] != NSOrderedAscending){ NSDictionary *infoDict = [[NSBundle mainBundle] infoDictionary]; return [[[infoDict objectForKey:@"NSAppTransportSecurity"] objectForKey:@"NSAllowsArbitraryLoads"] boolValue]; } return YES; }
應用辦法:
if ([self isHTTPEnable]) { NSLog(@"HTTP enable"); } else { NSLog(@"HTTP disable"); }
Swift 完成
func isHTTPEnable() -> Bool { let flag = UIDevice.currentDevice().systemVersion.compare("9.0.0", options: NSStringCompareOptions.NumericSearch) if (flag != .OrderedAscending) { guard let infoDict = NSBundle.mainBundle().infoDictionary else { return false } guard let appTransportSecurity = infoDict["NSAppTransportSecurity"] else { return false } guard let allowsArbitraryLoads = appTransportSecurity["NSAllowsArbitraryLoads"] else { return false } guard let res = allowsArbitraryLoads else { return false } return res as! Bool } return true }
應用辦法:
if self.isHTTPEnable() { print("HTTP enable") } else { print("HTTP disable") }
原文鏈接:http://blog.yourtion.com/is-IOS-app-enable-http.html
【斷定iOS運用能否開放HTTP權限的辦法】的相關資料介紹到這裡,希望對您有所幫助! 提示:不會對讀者因本文所帶來的任何損失負責。如果您支持就請把本站添加至收藏夾哦!