【问题标题】:Why is iOS 16/Xcode 14 causing UI responsiveness issues for apps that use location services and adMob?为什么 iOS 16/Xcode 14 会导致使用定位服务和 adMob 的应用出现 UI 响应问题?
【发布时间】:2022-11-10 23:56:11
【问题描述】:

我收到此错误:

如果在主线程上调用此方法,可能会导致 UI 无响应。相反,请考虑等待-locationManagerDidChangeAuthorization: 回调并首先检​​查authorizationStatus。”?

在 iOS 16 UI 之前还不错,现在确实显得有些滞后。

显然它与 AdMob 相关联。谷歌表示这是苹果的一个错误。 https://developer.apple.com/forums/thread/714467

最糟糕的是,在测试中,我实际上认为它确实会导致 UI 无响应。我真的不认为等待更新是一个好的解决方案。你们有没有人遇到过这个问题并采取了一些措施来解决它?

这就是我的代码的样子:

**      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")
}

**

【问题讨论】:

    标签: ios swift admob cllocationmanager ios16


    【解决方案1】:

    显示警告是因为您正在调用CLLocationManager.locationServicesEnabled()在主线程中,您已经在检查locationManager.authorizationStatus如果启用了位置服务,如果您需要在启用位置服务的情况下执行某些操作,您可以在案例 .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")
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-11-11
      • 2023-03-05
      • 1970-01-01
      • 2022-09-23
      • 1970-01-01
      • 1970-01-01
      • 2017-05-11
      • 1970-01-01
      相关资源
      最近更新 更多