【发布时间】:2017-11-29 18:27:56
【问题描述】:
我在 Xcode 9 beta、iOS 11 中使用谷歌地图。
我收到如下错误输出到日志:
主线程检查器:在后台线程上调用的 UI API:-[UIApplication applicationState] PID:4442,TID:837820,线程名称:com.google.Maps.LabelingBehavior,队列名称:com.apple.root.default-qos.overcommit,QoS:21
为什么会发生这种情况,因为我几乎可以肯定我没有更改代码中主线程的任何界面元素。
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)")
}
}
【问题讨论】:
-
在
mapView(_:didChange)中,您将print语句分派到主队列。你不是已经在主队列上了吗?如果没有,您也必须将animate调用发送到主队列。我建议在这些 UI 更新之前插入一些dispatchPrecondition(condition: .onQueue(.main)),以确保。 -
您说“我几乎可以肯定我不会从我的代码中的主线程更改任何界面元素。”我假设您的意思是“......来自任何后台线程。”
-
不是你的问题。我认为这是在他们的尽头。它停在“com.google.Maps.LabelingBehavior”中。我有同样的问题。
-
您好,是的,问题似乎出在 google 上,希望他们能尽快发布更新版本
-
@MattBlack 看看这个答案:stackoverflow.com/a/44392584/5912335
标签: swift google-maps xcode9-beta