You need to enable JavaScript to run this app. Xcode 12.5 beta2下CLGeocoder反地理编码报SSL错误无法获取用户位置信息
优惠活动
大模型
产品
解决方案
定价
更多

Xcode 12.5 beta2下CLGeocoder反地理编码报SSL错误无法获取用户位置信息

问题背景
  • 开发环境:Xcode Version 12.5 beta 2 (12E5234g)
  • 运行网络:家庭xFinity Wifi
  • 功能需求:应用每次启动运行时获取一次用户位置,解析得到对应的国家、州、县级行政区信息
  • 历史运行状态:功能此前正常,可触发位置权限申请弹窗,用户同意后即可顺利完成位置信息解析
现存异常
  • 可正常获取设备返回的经纬度坐标,但无法通过CLGeocoder的反地理编码能力拿到对应的实际地址信息
  • 反地理编码请求长时间无响应,疑似服务端链路超时
相关实现代码
private func getLocation(location: CLLocation) {
    CLGeocoder().reverseGeocodeLocation(location) { placemarks, _ in
        print("******  GLGeocoder Returns! (\(location))********")
        guard let placemark = placemarks?.first else {
            return
        }
        let country = placemark.country ?? ""
        UserLocation.country = country
        if placemark.administrativeArea != nil, USA.states != nil {
            UserLocation.state = USA.states![placemark.administrativeArea!]
        } else {
            NSLog("**** WARNING: Unable to access Location or State plist ****")
        }
        UserLocation.county = placemark.subAdministrativeArea
        UserLocation.coordinate = location.coordinate
        self.gotUserLocale = true
        print("My State: \(String(describing: UserLocation.state))")
    }
}
运行输出日志(约等待3分钟后生成)
******  GLGeocoder Returns! (<+36.97410000,-122.03080000> +/- 5.00m (speed -1.00 mps / course -1.00) @ 2/27/21, 11:28:49 AM Pacific Standard Time)********
******  GLGeocoder Returns! (<+36.97410000,-122.03080000> +/- 5.00m (speed -1.00 mps / course -1.00) @ 2/27/21, 11:28:49 AM Pacific Standard Time)********
******  GLGeocoder Returns! (<+36.97410000,-122.03080000> +/- 5.00m (speed -1.00 mps / course -1.00) @ 2/27/21, 11:28:49 AM Pacific Standard Time)********

Connection 1: received failure notification
Connection 1: failed to connect 3:-9816, reason -1
Connection 1: encountered error(3:-9816)
Connection 2: received failure notification
Connection 2: failed to connect 3:-9816, reason -1
Connection 2: encountered error(3:-9816)
[boringssl] boringssl_context_handle_fatal_alert(1800) [C3.1:2][0x127e2a4b0] read alert, level: fatal, description: inappropriate fallback
[boringssl] boringssl_session_handshake_incomplete(90) [C3.1:2][0x127e2a4b0] SSL library error
[boringssl] boringssl_session_handshake_error_print(41) [C3.1:2][0x127e2a4b0] Error: 4998591080:error:1000043e:SSL routines:OPENSSL_internal:TLSV1_ALERT_INAPPROPRIATE_FALLBACK:/Library/Caches/com.apple.xbs/Sources/boringssl_Sim/boringssl-351.100.8/ssl/tls_record.cc:594:SSL alert number 86
[boringssl] nw_protocol_boringssl_handshake_negotiate_proceed(767) [C3.1:2][0x127e2a4b0] handshake failed at state 12288: not completed
Connection 3: received failure notification
Connection 3: failed to connect 3:-9860, reason -1
Connection 3: encountered error(3:-9860)
Task <D87260CF-9E60-4355-8278-B2521BA3AF36>.<1> HTTP load failed, 0/0 bytes (error code: -1200 [3:-9860])
Task <D87260CF-9E60-4355-8278-B2521BA3AF36>.<1> finished with error [-1200] Error Domain=NSURLErrorDomain Code=-1200 "An SSL error has occurred and a secure connection to the server cannot be made." UserInfo={NSErrorFailingURLStringKey=https://disease.sh/v3/covid-19/jhucsse, NSLocalizedRecoverySuggestion=Would you like to connect to the server anyway?, _kCFStreamErrorDomainKey=3, _NSURLErrorFailingURLSessionTaskErrorKey=LocalDataTask <D87260CF-9E60-4355-8278-B2521BA3AF36>.<1>, _NSURLErrorRelatedURLSessionTaskErrorKey=(
    "LocalDataTask <D87260CF-9E60-4355-8278-B2521BA3AF36>.<1>"
), NSLocalizedDescription=An SSL error has occurred and a secure connection to the server cannot be made., NSErrorFailingURLKey=https://disease.sh/v3/covid-19/jhucsse, NSUnderlyingError=0x60000231db30 {Error Domain=kCFErrorDomainCFNetwork Code=-1200 "(null)" UserInfo={_kCFStreamPropertySSLClientCertificateState=0, _kCFNetworkCFStreamSSLErrorOriginalValue=-9860, _kCFStreamErrorDomainKey=3, _kCFStreamErrorCodeKey=-9860}}, _kCFStreamErrorCodeKey=-9860}

JHUAll - Received error: #function URLError(_nsError: Error Domain=NSURLErrorDomain Code=-1200 "An SSL error has occurred and a secure connection to the server cannot be made." UserInfo={NSErrorFailingURLStringKey=https://disease.sh/v3/covid-19/jhucsse, NSLocalizedRecoverySuggestion=Would you like to connect to the server anyway?, _kCFStreamErrorDomainKey=3, _NSURLErrorFailingURLSessionTaskErrorKey=LocalDataTask <D87260CF-9E60-4355-8278-B2521BA3AF36>.<1>, _NSURLErrorRelatedURLSessionTaskErrorKey=(
    "LocalDataTask <D87260CF-9E60-4355-8278-B2521BA3AF36>.<1>"
), NSLocalizedDescription=An SSL error has occurred and a secure connection to the server cannot be made., NSErrorFailingURLKey=https://disease.sh/v3/covid-19/jhucsse, NSUnderlyingError=0x60000231db30 {Error Domain=kCFErrorDomainCFNetwork Code=-1200 "(null)" UserInfo={_kCFStreamPropertySSLClientCertificateState=0, _kCFNetworkCFStreamSSLErrorOriginalValue=-9860, _kCFStreamErrorDomainKey=3, _kCFStreamErrorCodeKey=-9860}}, _kCFStreamErrorCodeKey=-9860})
已完成的验证项
  • 终端执行nscurl --ats-diagnostics https://apple.com --verbose 网络诊断通过
  • 可通过Safari正常访问日志中报错的公共服务地址,但Xcode工程内的应用无法正常发起对应请求
  • 应用可正常从其他公共数据源获取统计类数据,唯独反地理编码请求链路异常
附带环境输出

执行swift --version命令时出现的版本输出情况:

# 首次执行(含动态库重复符号警告)
/Users/ric> swift --version                                                 
objc[1556]: Class AMSupportURLConnectionDelegate is implemented in both /usr/lib/libauthinstall.dylib (0x208551868) and /System/Library/PrivateFrameworks/MobileDevice.framework/Versions/A/MobileDevice (0x1140442b8). One of the two will be used. Which one is undefined.
objc[1556]: Class AMSupportURLSession is implemented in both /usr/lib/libauthinstall.dylib (0x2085518b8) and /System/Library/PrivateFrameworks/MobileDevice.framework/Versions/A/MobileDevice (0x114044308). One of the two will be used. Which one is undefined.
objc[1557]: Class AMSupportURLConnectionDelegate is implemented in both /usr/lib/libauthinstall.dylib (0x208551868) and /System/Library/PrivateFrameworks/MobileDevice.framework/Versions/A/MobileDevice (0x1180442b8). One of the two will be used. Which one is undefined.
objc[1557]: Class AMSupportURLSession is implemented in both /usr/lib/libauthinstall.dylib (0x2085518b8) and /System/Library/PrivateFrameworks/MobileDevice.framework/Versions/A/MobileDevice (0x118044308). One of the two will be used. Which one is undefined.
Apple Swift version 5.4 (swiftlang-1205.0.24.6 clang-1205.0.19.54)
Target: arm64-apple-darwin20.4.0

# 第二次执行(无警告)
/Users/ric> swift --version
Apple Swift version 5.4 (swiftlang-1205.0.24.6 clang-1205.0.19.54)
Target: arm64-apple-darwin20.4.0
问题根因说明
  • 日志中的核心报错为TLS握手失败,对应错误码-1200、-9860、-9816,属于App Transport Security(ATS)拦截类问题,并非Apple地理编码服务宕机
  • Safari与应用、Xcode调试环境使用的TLS校验规则不一致,因此会出现浏览器可正常访问、应用内请求失败的现象
  • Xcode 12.5 beta 2属于早期测试版本,内置的BoringSSL TLS库存在协议回退校验逻辑过严的问题,会触发inappropriate fallback类TLS告警
  • 家庭xFinity网络的透明代理可能在TLS握手阶段做了证书替换,其证书链不符合应用内置的严格校验规则,直接被拦截
  • 执行Swift命令时出现的动态库重复符号警告属于Xcode测试版本的已知小问题,与本次反地理编码失败无直接关联
可行解决方案
  • 检查应用Info.plist中的ATS配置,为需要访问的地理编码服务域名补充例外规则,匹配实际网络环境的TLS校验要求
  • 将Xcode从beta测试版本切换到正式稳定版,排除内置TLS库的版本兼容问题
  • 临时切换至其他网络环境(如手机热点)验证,排除家庭网络代理导致的TLS链路拦截
  • 为反地理编码请求补充错误回调与超时设置,避免长时间无响应的等待
链路状态检测实现思路
  • 可使用系统原生网络能力检测基础网络连通性
  • 针对目标服务单独发起轻量探测请求,校验TLS握手是否成功,避免仅通过通用可达性判断链路状态
  • 对地理编码服务链路与其他业务数据链路做独立状态监控,区分通用网络问题与特定服务的ATS拦截问题

内容的提问来源于stack exchange,提问作者Frederick C. Lee

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.11.01 14:06:04