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

iOS 16.2初始化GMSMapView时应用崩溃,UIKit也存在该问题

初始化GMSMapView时应用崩溃(UIKit/ SwiftUI均出现)

问题描述

初始化GMSMapView时应用直接崩溃,UIKit环境下同样复现。已尝试清理Pods、更新Pods、清理项目缓存,但问题依旧。上周应用运行完全正常。

环境信息

  • iOS版本:16.2
  • 设备:iPhone 14 Plus
  • GoogleMaps版本:7.4.0

代码片段

func makeUIView(context: Context) -> GMSMapView {
    let camera: GMSCameraPosition = .init(latitude: currentLocation.latitude, longitude: currentLocation.longitude, zoom: 16.0)

    // 崩溃位置
    let mapView = GMSMapView.map(withFrame: CGRect.zero, camera: camera)
    mapView.delegate = context.coordinator
    mapView.isMyLocationEnabled = true
    context.coordinator.mapView = mapView

    self.updateCircle(mapView: mapView)

    return mapView
}

崩溃日志

Date/Time:           2024-02-27 20:42:46.7377 -0600
Launch Time:         2024-02-27 20:36:28.3196 -0600
OS Version:          macOS 13.4.1
Release Type:        User

Exception Type:  EXC_CRASH (SIGABRT)
Exception Codes: 0x0000000000000000, 0x0000000000000000
Triggered by Thread:  17

Thread 0::  Dispatch queue: com.apple.main-thread
0   ???                                    0x1491f5f50 ???
1   ???                                    0x1491f5da0 ???
2   app-name                               0x105075b60 __InstrumentSessionWithConfigurationDelegateDelegateQueue_block_invoke + 48
3   app-name                               0x11311ee34 -[GMSx_GTMSessionFetcher createSessionWithDelegate:sessionIdentifier:] + 569
4   app-name                               0x11311dedb -[GMSx_GTMSessionFetcher beginFetchMayDelay:mayAuthorize:mayDecorate:] + 2019
5   app-name                               0x1130de6b0 GMSAllSDKCheckForUpdatesImpl + 281
6   libdispatch.dylib                      0x1611fef5b _dispatch_client_callout + 8
7   libdispatch.dylib                      0x1612005b5 _dispatch_once_callout + 66
8   app-name                               0x1130387eb -[GMSServices initWithDisplayLink:resourceCache:clearcutClient:dataURL:cachesURL:options:] + 3558
9   app-name                               0x11301844f invocation function for block in CompleteInit(GMSAsyncInitServices*) + 241
10  app-name                               0x1130181e3 CompleteInit(GMSAsyncInitServices*) + 345
11  app-name                               0x11301825b -[GMSAsyncInitServices services] + 67
12  app-name                               0x11303758d +[GMSServices sharedServicesSync] + 136
13  app-name                               0x113023c89 -[GMSMapView initWithFrame:] + 40
14  app-name                               0x104d79b6d @nonobjc GMSMapView.init(frame:) + 61
15  app-name                               0x104d76f2a GMSMapView.__allocating_init(frame:) + 74
16  app-name                               0x10b442d26 AddressMapKit.makeUIView(context:) + 278 (AddressMapKit.swift:27)
17  app-name                               0x10b443299 protocol witness for UIViewRepresentable.makeUIView(context:) in conformance AddressMapKit + 73

解决方向

  1. 检查API密钥配置

    • 确认Info.plist中的Google Maps API密钥是否有效,是否存在过期、配额耗尽或权限变更的情况。
    • 登录Google Cloud控制台,验证Maps SDK for iOS服务是否已启用,相关配额是否正常。
  2. 调整SDK初始化时机

    • 崩溃发生在GMSServices初始化阶段,可尝试在App启动时提前同步初始化:
      func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
          GMSServices.provideAPIKey("YOUR_API_KEY")
          _ = GMSServices.sharedServicesSync()
          return true
      }
      
  3. 回退SDK版本

    • 当前7.4.0版本可能存在兼容性问题,回退到上周正常运行的版本(如7.3.0),修改Podfile后执行pod install:
      pod 'GoogleMaps', '~> 7.3.0'
      
  4. 排查网络相关问题

    • 崩溃日志涉及GTMSessionFetcher,说明SDK联网检查更新失败。确认设备网络正常,无代理拦截;检查Info.plist中NSAppTransportSecurity配置是否允许连接Google服务器。
  5. 清理缓存

    • 卸载App后重新安装,或手动清理App沙盒内的Google Maps缓存文件,避免旧缓存导致初始化异常。

内容的提问来源于stack exchange,提问作者Carlos Andres Ponce

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.28 21:27:03