Ios 我的应用程序不能';将xcode更新为7.2后,无法连接到webservice
我运行应用程序时遇到问题。当我将xcode版本升级到7.2时,我的应用程序在xcode 6.4中成功运行,它无法连接到我的Web服务。 我想用来自webservice的数据填充位置列表。我已经调试了代码,但它总是进入连接错误状态。这是我的密码:Ios 我的应用程序不能';将xcode更新为7.2后,无法连接到webservice,ios,xcode,web-services,Ios,Xcode,Web Services,我运行应用程序时遇到问题。当我将xcode版本升级到7.2时,我的应用程序在xcode 6.4中成功运行,它无法连接到我的Web服务。 我想用来自webservice的数据填充位置列表。我已经调试了代码,但它总是进入连接错误状态。这是我的密码: - (void) locatoins { NSString *urlString = @"http://41.128.183.109:9090/api/Data/Getalllocations"; NSURL *url = [NSUR
- (void) locatoins {
NSString *urlString = @"http://41.128.183.109:9090/api/Data/Getalllocations";
NSURL *url = [NSURL URLWithString:urlString];
NSURLRequest *request = [NSURLRequest requestWithURL:url cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:20];
[NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
if (connectionError) {
[SVProgressHUD dismiss];
LocationsViewController *D;
UIAlertView *alert = [[UIAlertView alloc]initWithTitle: @"Request Time Out"message: @"Network Connection Error"delegate: D cancelButtonTitle:@"Dismiss"otherButtonTitles:@"Cancel",nil];
[alert setTag:1];
} else {
NSArray *json = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:nil];
NSMutableArray *result = [NSMutableArray array];
for (NSDictionary *obj in json) {
Location *location = [[Location alloc] initWithDictionary:obj];
[result addObject:location];
}
[self.delegate dataHandlerDidFininshGettingLocations:result];
}
}];
}
请告知。您是否也在控制台中收到一个错误,显示“CFNetwork SSLHandshake失败”?我想这可能是ATS的问题。iOS9(所以,Xcode 7)强制您使用https而不是http,并且您的服务器应该具有有效的ssl证书 通过在Info.plist文件中添加异常或通配符,可以绕过应用程序传输安全:
<key>NSAppTransportSecurity</key>
<dict>
<key>NSExceptionDomains</key>
<dict>
<key>yourserver.com</key>
<dict>
<!--Include to allow subdomains-->
<key>NSIncludesSubdomains</key>
<true/>
<!--Include to allow HTTP requests-->
<key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key>
<true/>
<!--Include to specify minimum TLS version-->
<key>NSTemporaryExceptionMinimumTLSVersion</key>
<string>TLSv1.1</string>
</dict>
</dict>
</dict>
NSAppTransportSecurity
NSExceptionDomains
yourserver.com
n包括多个域
NSTemporary ExceptionalLowsInSecureHttpLoads
NSTemporaryExceptionMinimumTLSVersion
TLSv1.1
或
NSAppTransportSecurity
NSAllowsArbitraryLoads
有关iOS 9中ATS更改的更多详细信息@prime只要不破坏info.plist的结构,您可以在任何地方添加它。例如,在最后,就在
<key>NSAppTransportSecurity</key>
<dict>
<!--Include to allow all connections (DANGER)-->
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>