SoFunction
Updated on 2025-04-12

How to determine whether an iOS application opens HTTP permissions

Starting from iOS9, the new feature requires app access to network requests and the HTTPS protocol must be used. But can we determine whether the developer allows HTTP requests, so that the following information will not pop up when 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 file.

This requirement is actually something that has been working on HTTPDNS related recently. It can only be requested through the HTTP interface, but I hope to determine whether the application allows HTTP access. If allowed, the HTTPDNS related functions will be enabled.

The solution is relatively simple, but it is actually reading have a look NSAppTransportSecurity Whether 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 implementation

func isHTTPEnable() -> Bool {
 let flag = ().("9.0.0", options: )
 if (flag != .OrderedAscending) {
 guard let infoDict = ().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 () {
 print("HTTP enable")
} else {
 print("HTTP disable")
}

Original link:/