如何解决 MapKit 中的 bad certificate 错误
How to solve the bad certificate error in MapKit
我正在尝试在我的应用程序中使用 MapKit framework
。我需要获得路线积分。为此,我写了以下内容:
let directions = MKDirections(request: request)
directions.calculate { response, error in
if error != nil {
print("Error getting directions ", error.debugDescription)
} else {
guard let response = response else { return }
completion(response.routes[0])
}
}
但是,我收到错误消息:
Error getting directions Optional(Error Domain=NSURLErrorDomain
Code=-1202 "The certificate for this server is invalid. You might be
connecting to a server that is pretending to be “gsp-ssl.ls.apple.com”
which could put your confidential information at risk."
UserInfo={NSErrorFailingURLKey=https://gsp-ssl.ls.apple.com/directions.arpc,
NSLocalizedRecoverySuggestion=Would you like to connect to the server
anyway?, NSUnderlyingError=0x6000014bce40 { Error
Domain=kCFErrorDomainCFNetwork Code=-1202 "(null)"
UserInfo={_kCFStreamPropertySSLClientCertificateState=0,
_kCFNetworkCFStreamSSLErrorOriginalValue=-9843, _kCFStreamErrorDomainKey=3, _kCFStreamErrorCodeKey=-9843, kCFStreamPropertySSLPeerCertificates=()}},
_kCFStreamErrorCodeKey=-9843, NSErrorPeerCertificateChainKey=(), NSLocalizedDescription=The certificate for this server is invalid. You
might be connecting to a server that is pretending to be
“gsp-ssl.ls.apple.com” which could put your confidential information
at risk., NSErrorClientCertificateStateKey=0,
NSErrorFailingURLStringKey=https://gsp-ssl.ls.apple.com/directions.arpc,
_kCFStreamErrorDomainKey=3})
我已经编辑了 Info.plist 文件:
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
<key>NSAllowsLocalNetworking</key>
<true/>
<key>NSExceptionDomains</key>
<dict>
<key>gsp-ssl.ls.apple.com</key>
<dict>
<key>NSRequiresCertificateTransparency</key>
<true/>
<key>NSExceptionRequiresForwardSecrecy</key>
<false/>
<key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key>
<true/>
<key>NSExceptionAllowsInsecureHTTPLoads</key>
<true/>
</dict>
</dict>
</dict>
这就是浏览器向我显示的内容:
向 Apple 报告错误后,问题得到解决,现在没有 VPN 一切正常。
我正在尝试在我的应用程序中使用 MapKit framework
。我需要获得路线积分。为此,我写了以下内容:
let directions = MKDirections(request: request)
directions.calculate { response, error in
if error != nil {
print("Error getting directions ", error.debugDescription)
} else {
guard let response = response else { return }
completion(response.routes[0])
}
}
但是,我收到错误消息:
Error getting directions Optional(Error Domain=NSURLErrorDomain Code=-1202 "The certificate for this server is invalid. You might be connecting to a server that is pretending to be “gsp-ssl.ls.apple.com” which could put your confidential information at risk." UserInfo={NSErrorFailingURLKey=https://gsp-ssl.ls.apple.com/directions.arpc, NSLocalizedRecoverySuggestion=Would you like to connect to the server anyway?, NSUnderlyingError=0x6000014bce40 { Error Domain=kCFErrorDomainCFNetwork Code=-1202 "(null)" UserInfo={_kCFStreamPropertySSLClientCertificateState=0, _kCFNetworkCFStreamSSLErrorOriginalValue=-9843, _kCFStreamErrorDomainKey=3, _kCFStreamErrorCodeKey=-9843, kCFStreamPropertySSLPeerCertificates=()}}, _kCFStreamErrorCodeKey=-9843, NSErrorPeerCertificateChainKey=(), NSLocalizedDescription=The certificate for this server is invalid. You might be connecting to a server that is pretending to be “gsp-ssl.ls.apple.com” which could put your confidential information at risk., NSErrorClientCertificateStateKey=0, NSErrorFailingURLStringKey=https://gsp-ssl.ls.apple.com/directions.arpc, _kCFStreamErrorDomainKey=3})
我已经编辑了 Info.plist 文件:
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
<key>NSAllowsLocalNetworking</key>
<true/>
<key>NSExceptionDomains</key>
<dict>
<key>gsp-ssl.ls.apple.com</key>
<dict>
<key>NSRequiresCertificateTransparency</key>
<true/>
<key>NSExceptionRequiresForwardSecrecy</key>
<false/>
<key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key>
<true/>
<key>NSExceptionAllowsInsecureHTTPLoads</key>
<true/>
</dict>
</dict>
</dict>
这就是浏览器向我显示的内容:
向 Apple 报告错误后,问题得到解决,现在没有 VPN 一切正常。