运行我的应用时遇到问题。当我将我的xcode版本升级到7.2时,我的应用程序在xcode 6.4中成功运行它无法连接到我的webservise。 我想用webservice中的数据填充位置列表。我已经调试了我的代码,但它总是转到连接错误状态。这是我的代码:
- (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];
}
}];
}
请告知。
答案 0 :(得分:1)
您是否也在控制台中收到错误消息“CFNetwork SSLHandshake failed”?我认为这可能是一个ATS问题。 iOS 9(因此,Xcode 7)强制您使用https而不是http,并且您的服务器应该具有有效的ssl证书。
您可以通过在Info.plist文件中添加例外或通配符来绕过App Transport Security:
<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>
或
<key>NSAppTransportSecurity</key>
<dict>
<!--Include to allow all connections (DANGER)-->
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
有关iOS 9 {A {3}}
中ATS更改的更多详细信息