Ways to determine whether IOS applications open HTTP permissions _ios

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.