将Xcode更新为7.0或iOS 9.0时遇到问题。它以某种方式开始给我标题错误
“无法加载资源,因为应用程序传输安全策略需要使用安全连接”
Web服务方法:
-(void)ServiceCall:(NSString*)ServiceName :(NSString *)DataString
{
NSURLSessionConfiguration *sessionConfiguration = [NSURLSessionConfiguration defaultSessionConfiguration];
[sessionConfiguration setAllowsCellularAccess:YES];
[sessionConfiguration setHTTPAdditionalHeaders:@{ @"Accept" : @"application/json" }];
NSURLSession *session = [NSURLSession sessionWithConfiguration:sessionConfiguration];
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"%@",ServiceURL]];
NSLog(@"URl %@%@",url,DataString);
// Configure the Request
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
[request setValue:[NSString stringWithFormat:@"%@=%@", strSessName, strSessVal] forHTTPHeaderField:@"Cookie"];
request.HTTPBody = [DataString dataUsingEncoding:NSUTF8StringEncoding];
request.HTTPMethod = @"Post";
// post the request and handle response
NSURLSessionDataTask *postDataTask = [session dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error)
{
// Handle the Response
if(error)
{
NSLog(@"%@",[NSString stringWithFormat:@"Connection failed: %@", [error description]]);
// Update the View
dispatch_async(dispatch_get_main_queue(), ^{
// Hide the Loader
[MBProgressHUD hideHUDForView:[[UIApplication sharedApplication] delegate].window animated:YES];
});
return;
}
NSArray * cookies = [[NSHTTPCookieStorage sharedHTTPCookieStorage] cookiesForURL:request.URL];
for (NSHTTPCookie * cookie in cookies)
{
NSLog(@"%@=%@", cookie.name, cookie.value);
strSessName=cookie.name;
strSessVal=cookie.value;
}
NSString *retVal = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
}];
[postDataTask resume];
}
对于Xcode早期版本和iOS早期版本,该服务运行良好,但是当我更新到iOS 9.0上的Xcode 7.0时,它开始给我类似我在调用上述Web服务方法时出现的问题。我收到的记录错误是:
连接失败:错误域= NSURLErrorDomain代码= -1022“无法加载资源,因为应用程序传输安全策略需要使用安全连接。” UserInfo = {NSUnderlyingError = 0x7fada0f31880 {Error Domain = kCFErrorDomainCFNetwork代码= -1022“(null)”},NSErrorFailingURLStringKey = MyServiceURL,NSErrorFailingURLKey = MyServiceURL,NSLocalizedDescription =无法加载资源,因为应用传输安全策略需要使用安全的安全性连接。}
我已经尝试过以下问题和解答,但是没有得到任何结果,是否有任何高级想法可以删除该服务调用错误?