You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

iOS15仅Release模式下GMSAutocompleteViewController崩溃咨询

GMSAutocompleteViewController iOS15+ Release模式崩溃问题

问题表现

  • 调用present展示GMSAutocompleteViewController时触发崩溃,新建独立空白测试应用仍可稳定复现
  • 崩溃仅发生在Release构建模式,Debug模式下功能运行完全正常
  • 系统版本特征:iOS 15以下所有版本无异常,仅iOS 15及以上版本触发崩溃
  • 已在AppDelegate中完成API Key合法配置,Debug模式下地址自动补全功能可正常调用

相关实现代码如下:

let autocompleteController = GMSAutocompleteViewController()
autocompleteController.delegate = self
autocompleteController.modalPresentationStyle = .overFullScreen
present(autocompleteController, animated: true, completion: nil)

崩溃日志关键信息

复现测试环境:

  • CoreSimulator 802.6.1
  • 测试设备:iPhone 13 Pro Max 模拟器
  • 系统版本:iOS 15.5 (19F70)

崩溃核心原因:

应用因未捕获NSException类型异常终止,异常类型为NSGenericException,错误信息:*** Collection <NSConcreteMapTable: 0x7f780792d7d0> was mutated while being enumerated.,即集合对象在枚举遍历过程中被修改。

根因说明

该问题是旧版本Google Places SDK的已知内部缺陷:SDK内部维护关联对象的NSConcreteMapTable存在线程安全问题,Release模式下编译器开启优化后,代码执行时序变化,遍历集合的过程中触发了对象修改逻辑,直接触发系统集合保护的崩溃。Debug模式下编译优化关闭、iOS15以下系统内部视图加载时序不同,因此不会触发该问题。

可落地解决方案

  • 最优方案:升级Google Places SDK到最新稳定版本,官方已在后续版本中修复该线程安全问题
  • 临时规避方案1:若暂时无法升级SDK,可将Release配置下对应调用代码文件的编译优化级别从-Os/-O2调整为-Onone,消除优化带来的时序问题
  • 临时规避方案2:调整控制器弹出逻辑,将present操作延迟0.1s派发到主队列执行,修改后代码如下:
let autocompleteController = GMSAutocompleteViewController()
autocompleteController.delegate = self
autocompleteController.modalPresentationStyle = .overFullScreen
DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) {
    self.present(autocompleteController, animated: true, completion: nil)
}

内容的提问来源于stack exchange,提问作者muhammad awais

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.09.03 00:51:27