2016-02-23 23 views
1

我試圖使用雙向SSL與服務進行通信。WatchOS2.1上的雙向SSL失敗,但iOS9.1上的相同代碼有效

我發現連接在客戶端(手錶)提供客戶端證書後,立即取消了,通過調用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); 
    } 
} 
+0

你能顯示更多的代碼嗎? – Raptor

回答

1

。 這是Watch OS的限制。現在不支持雙向SSL。

+0

仍然不能在watchOS 3 GM中工作。 – Florian

相關問題