NSURLSessionでSSL通信時に "Error Domain=NSURLErrorDomain Code=-1202" 発生は、端末の時刻設定が原因

APNsのdeviceTokenを Azure Notification Hub へ登録しようとしたら、Error Domain=NSURLErrorDomain Code=-1202が発生。

```
Error Domain=NSURLErrorDomain Code=-1202 "The certificate for this server is invalid. You might be connecting to a server that is pretending to be “x.servicebus.windows.net” which could put your confidential information at risk." UserInfo={NSURLErrorFailingURLPeerTrustErrorKey=<SecTrustRef: 0x13f581150>, NSLocalizedRecoverySuggestion=Would you like to connect to the server anyway?, _kCFStreamErrorDomainKey=3, _kCFStreamErrorCodeKey=-9814, NSErrorPeerCertificateChainKey=<CFArray 0x13f57d4c0 [0x1a1986150]>{type = immutable, count = 2, values = (
	0 : <cert(0x13f57e9e0) s: notificationhub.windows.net i: Microsoft IT SSL SHA2>
	1 : <cert(0x13f580780) s: Microsoft IT SSL SHA2 i: Baltimore CyberTrust Root>
)}, NSUnderlyingError=0x13f581740 {Error Domain=kCFErrorDomainCFNetwork Code=-1202 "The certificate for this server is invalid. You might be connecting to a server that is pretending to be “x.servicebus.windows.net” which could put your confidential information at risk." UserInfo={NSErrorFailingURLStringKey=https://x.servicebus.windows.net/A/Registrations/?$filter=deviceToken+eq+'X'&api-version=2013-04, NSLocalizedRecoverySuggestion=Would you like to connect to the server anyway?, _kCFNetworkCFStreamSSLErrorOriginalValue=-9814, kCFStreamPropertySSLPeerCertificates=<CFArray 0x13f57d4c0 [0x1a1986150]>{type = immutable, count = 2, values = (
	0 : <cert(0x13f57e9e0) s: notificationhub.windows.net i: Microsoft IT SSL SHA2>
	1 : <cert(0x13f580780) s: Microsoft IT SSL SHA2 i: Baltimore CyberTrust Root>
)}, _kCFStreamPropertySSLClientCertificateState=0, kCFStreamPropertySSLPeerTrust=<SecTrustRef: 0x13f581150>, NSLocalizedDescription=The certificate for this server is invalid. You might be connecting to a server that is pretending to be “x.servicebus.windows.net” which could put your confidential information at risk., _kCFStreamErrorDomainKey=3, NSErrorFailingURLKey=https://x.servicebus.windows.net/A/Registrations/?$filter=deviceToken+eq+'X'&api-version=2013-04, _kCFStreamErrorCodeKey=-9814}}, NSLocalizedDescription=The certificate for this server is invalid. You might be connecting to a server that is pretending to be “x.servicebus.windows.net” which could put your confidential information at risk., NSErrorFailingURLKey=https://x.servicebus.windows.net/A/Registrations/?$filter=deviceToken+eq+'X'&api-version=2013-04, NSErrorFailingURLStringKey=https://x.servicebus.windows.net/A/Registrations/?$filter=deviceToken+eq+'X'&api-version=2013-04, NSErrorClientCertificateStateKey=0}
```

**"The certificate for this server is invalid. You might be connecting to a server that is pretending to be “x.servicebus.windows.net” which could put your confidential information at risk."**


ATS (App Transport Security)の設定に間違いがあるのかと試したが問題ない。

```Error Domain=NSURLErrorDomain Code=-1202```は、自己認証証明書等、証明書が正しくない場合に発生するらしい。

```Microsoft IT SSL SHA2 i: Baltimore CyberTrust Root```の記述が見つかるので、証明書は正しい。


Stack Overflow によると...

linkedin - Error Domain=NSURLErrorDomain Code=-1202 iPhone - Stack Overflow http://stackoverflow.com/questions/18415157/error-domain-nsurlerrordomain-code-1202-iphone

> I got it by losting my whole day, It was my device setting that need to change the date and time , nad set it automatically ON for current time zone .

iPhoneの日付と時刻がずれていると発生するらしい。
自動設定にして正しい日付と時刻に戻すとエラーは発生しなくなった。