为什么iOS 16/Xcode 14会导致使用位置服务和adMob的应用程序出现UI响应性问题?

3
我遇到了这个错误:
这种方法如果在主线程上调用可能会导致界面无响应。相反,考虑等待-locationManagerDidChangeAuthorization:回调并首先检查authorizationStatus。
在iOS 16之前,界面是正常的,现在看起来确实有点卡顿。
显然这与AdMob有关。谷歌表示这是苹果的一个bug。https://developer.apple.com/forums/thread/714467 最糟糕的是,在测试中我真的认为它会导致界面无响应。我真的不认为等待更新是一个好的解决办法。
你们有没有遇到过这个问题,并且采取了什么措施来解决?
这是我的代码样式:
if CLLocationManager.locationServicesEnabled() {
    let authorizationStatus: CLAuthorizationStatus
    if #available(iOS 14, *) {
        authorizationStatus = locationManager.authorizationStatus
    } else {
        authorizationStatus = CLLocationManager.authorizationStatus()
    }

    switch authorizationStatus {
    case .authorizedAlways, .authorizedWhenInUse:
    case .notDetermined:
    case .restricted:
    case .denied:
    @unknown default:
        print("Location services are not enabled")
    }

Google和此帖子的超链接之间有什么联系? - greybeard
1个回答

0
警告是因为您在主线程中调用了CLLocationManager.locationServicesEnabled(),您已经使用locationManager.authorizationStatus检查了位置服务是否启用,如果您需要执行一些启用位置服务的操作,则可以在case .authorizedAlways, .authorizedWhenInUse:中执行。
     let authorizationStatus: CLAuthorizationStatus
    if #available(iOS 14, *) {
        authorizationStatus = locationManager.authorizationStatus
    } else {
        authorizationStatus = CLLocationManager.authorizationStatus()
    }

    switch authorizationStatus {
    case .authorizedAlways, .authorizedWhenInUse:
    // your code here
    case .notDetermined:
    case .restricted:
    case .denied:
    @unknown default:
        print("Location services are not enabled")

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接