【发布时间】:2016-02-23 04:19:09
【问题描述】:
我试图通过双向 SSL 与服务通信。
我发现客户端(手表)通过调用completeHandler(NSURLSessionAuthChallengeUseCredential, credential)提供客户端证书后立即取消连接
得到的错误是:
NSURLErrorDomain 代码=-999 已取消
但我尝试在手机上运行相同的代码,它确实成功了。 除此之外,其他请求在手表上运行良好。
由于 WatchOS 和 iOS 上的框架不同,我想知道这是否可能是 WatchOS 的问题?或者手表有什么特别需要配置的吗?
这里是代码
- (void)URLSession:(NSURLSession *)session didReceiveChallenge:(NSURLAuthenticationChallenge *)challenge completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition, NSURLCredential *))completionHandler
{
NSURLProtectionSpace *protectionSpace = [challenge protectionSpace];
NSString *authMethod = [protectionSpace authenticationMethod];
if (authMethod == NSURLAuthenticationMethodServerTrust) {
completionHandler(NSURLSessionAuthChallengeUseCredential, [NSURLCredential credentialForTrust:serverTrust]);
} else if (authMethod == NSURLAuthenticationMethodClientCertificate) {
// cancelled immediately after calling the method below.
completionHandler(NSURLSessionAuthChallengeUseCredential, self.credential);
} else {
completionHandler(NSURLSessionAuthChallengePerformDefaultHandling, nil);
}
}
【问题讨论】:
-
你能显示更多代码吗?
标签: ssl ssl-certificate watchos-2 ios9.1