我试图用双向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);
}
}发布于 2016-04-06 06:33:23
得到苹果工程师的确认。这是对Watch OS的限制。目前不支持双向SSL。
https://stackoverflow.com/questions/35568750
复制相似问题