From the IOS9, the new features require the APP to access the network request, using HTTPS protocol. But whether or not the developer will allow HTTP requests will not fail to eject the following message at the time the request is initiated:
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.
This requirement is actually a recent httpdns related things, can only be requested through the HTTP interface, but would like to determine whether the application allows HTTP access, if allowed to open HTTPDNS-related functions.
The solution is relatively simple, is actually read info.plist to see if nsapptransportsecurity is YES.
OBJECTIVE-C implementation
-(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
}
How to use:
if ([self ishttpenable]) {
NSLog (@ "http enable");
} else {
NSLog (@ "http disable");
}
Swift realizes
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
}
How to use:
If Self.ishttpenable () {
print ("http Enable")
} else {
print ("http disable")
}
Original link: http://blog.yourtion.com/is-ios-app-enable-http.html