主线程检查器:在后台线程上调用UI API: - [UIApplication applicationState] [英] Main Thread Checker: UI API called on a background thread: -[UIApplication applicationState]

查看:7567
本文介绍了主线程检查器:在后台线程上调用UI API: - [UIApplication applicationState]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我收到一个输出到日志的错误,如下所示:


主线程检查器:在后台线程上调用的UI API: - [UIApplication applicationState]
PID:4442,TID:837820,线程名称:com.google .Maps.LabelingBehavior,队列名称:com.apple.root.default-qos.overcommit,QoS:21


为什么会这样发生在我几乎可以肯定的情况下,我并没有改变代码中主线程的任何接口元素。

  









让locationManager = CLLocationManager()
$ b $ override $ $ b locationManager.requestWhenInUseAuthorization()

如果CLLocationManager.locationServicesEnabled(){

locationManager.desiredAccuracy = kCLLocationAccuracyNearestTenMet ers
locationManager.startUpdatingLocation()
}

viewMap.delegate = self

let camera = GMSCameraPosition.camera(withLatitude:53.7931183329367,longitude: - 1.53649874031544,zoom:17.0)


viewMap.animate(to:camera)




func locationManager经理:CLLocationManager,didUpdateLocations位置:[CLLocation]){
let locValue:CLLocationCoordinate2D = manager.location!.coordinate
print(locations = \(locValue.latitude)\(locValue.longitude) )
}

func mapView(_ mapView:GMSMapView,willMove gesture:Bool){


}

func mapView(_ mapView:GMSMapView,idleAt position:GMSCameraPosition){

if(moving> 1){
moving = 1
UIView.animate(withDuration:0.5,delay:0,animations:{

self.topBarConstraint.constant = self.topBarConstraint.constant +( self.topBar.bounds.height / 2)

self.bottomHalfConstraint.constant = self.bottomHalfConstraint.constant +(self.topBar.bounds.height / 2)

self .view.layoutIfNeeded()
},完成:无)
}
移动= 1
}


//相机更改位置这个方法会每次调用
func mapView(_mapView:GMSMapView,didChange position:GMSCameraPosition){
moving = moving + 1
if(moving == 2){


UIView.animate(withDuration:0.5,delay:0,animations:{


self.topBarConstraint.constant = self.topBarConstraint.constant - (self.topBar .bounds.height / 2)

self.bottomHalfConstraint.constant = self。 bottomHalfConstraint.constant - (self.topBar.bounds.height / 2)


self.view.layoutIfNeeded()
},completion:nil)
}
DispatchQueue.main.async {

print(Moving:\(moving)Latitude:\(self.viewMap.camera.target.latitude))
print( Moving:\(moving)Longitude:\(self.viewMap.camera.target.longitude))
}
}




解决方案

我的答案假定您已经检查过,以确保您的代码不会修改UI后台线程。

Xcode 9,10.29.17


  1. 更新你的豆荚。许多Cocoapod开发人员正在赶上已故的线程检查器。

  2. 如果可可豆开发人员没有更新他们的豆荚,那么您可以尝试联系他们或建议修改。

Xcode 9 beta $ b

注意到xcode 9测试版的新运行时崩溃与xcode 8没有一样。如果您不希望程序崩溃,则可以返回到xcode 8或禁用线程检查器,直到Apple修复新的崩溃或者你的豆荚不再触发它。

I am using google maps in Xcode 9 beta, iOS 11.

I am getting an error outputted to the log as follows:

Main Thread Checker: UI API called on a background thread: -[UIApplication applicationState] PID: 4442, TID: 837820, Thread name: com.google.Maps.LabelingBehavior, Queue name: com.apple.root.default-qos.overcommit, QoS: 21

Why would this be occurring as I am almost certain I'm not altering any interface elements from the main thread in my code.

 override func viewDidLoad() {

    let locationManager = CLLocationManager()


    locationManager.requestAlwaysAuthorization()


    locationManager.requestWhenInUseAuthorization()

        if CLLocationManager.locationServicesEnabled() {

            locationManager.desiredAccuracy = kCLLocationAccuracyNearestTenMeters
            locationManager.startUpdatingLocation()
        }

      viewMap.delegate = self

     let camera = GMSCameraPosition.camera(withLatitude: 53.7931183329367, longitude: -1.53649874031544, zoom: 17.0)


        viewMap.animate(to: camera)


    }

    func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
        let locValue:CLLocationCoordinate2D = manager.location!.coordinate
        print("locations = \(locValue.latitude) \(locValue.longitude)")
    }

    func mapView(_ mapView: GMSMapView, willMove gesture: Bool) {


    }

    func mapView(_ mapView: GMSMapView, idleAt position: GMSCameraPosition) {

        if(moving > 1){
            moving = 1
        UIView.animate(withDuration: 0.5, delay: 0, animations: {

            self.topBarConstraint.constant = self.topBarConstraint.constant + (self.topBar.bounds.height / 2)

            self.bottomHalfConstraint.constant = self.bottomHalfConstraint.constant + (self.topBar.bounds.height / 2)

            self.view.layoutIfNeeded()
        }, completion: nil)
    }
         moving = 1
    }


    // Camera change Position this methods will call every time
    func mapView(_ mapView: GMSMapView, didChange position: GMSCameraPosition) {
        moving = moving + 1
        if(moving == 2){


            UIView.animate(withDuration: 0.5, delay: 0, animations: {


                self.topBarConstraint.constant = self.topBarConstraint.constant - (self.topBar.bounds.height / 2)

                self.bottomHalfConstraint.constant = self.bottomHalfConstraint.constant - (self.topBar.bounds.height / 2)


                self.view.layoutIfNeeded()
            }, completion: nil)
        }
        DispatchQueue.main.async {

            print("Moving: \(moving) Latitude: \(self.viewMap.camera.target.latitude)")
            print("Moving: \(moving)  Longitude: \(self.viewMap.camera.target.longitude)")
        }
    }

解决方案

My answer assumes you have already checked to make sure your codes are not modifying the UI from a background thread.

Xcode 9, 10.29.17

  1. Update your pods. Many Cocoapod developers are catching up with the late thread checker.
  2. If the cocoa pod developer isn't updating their pod, then you can try contacting them or suggest modifications.

Xcode 9 beta

I have noticed a newly built in run time crash with xcode 9 beta that isn't there with xcode 8. If you do not want your program to crash, you can go back to xcode 8 or disable the thread checker until either Apple fixes the new crash or your pods no longer trigger it.

这篇关于主线程检查器:在后台线程上调用UI API: - [UIApplication applicationState]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆