【发布时间】:2017-06-23 13:15:14
【问题描述】:
我有一个执行地理围栏的应用程序。当我在模拟器(Xcode 8.3.3 和 Xcode 9)中运行它时,一切似乎都可以正常工作,但我的 CLLocationManager didEnterRegion 从未被调用。
当我在我的 iPhone 上运行应用程序时,它被调用得很好,无论是在现实世界中(进入一个区域)还是在 Xcode 中通过位置模拟。
知道为什么会这样吗?
我发现的一个区别是模拟器只支持在使用时监控位置,所以我必须进行设置,所以我的 plist 文件中有两个权限字符串,但除此之外我很难过。
由于我没有提供代码(它太复杂并且分布在我的应用程序中),让我注意模拟器中的工作:
在我的应用程序方案中,我选中了“允许位置模拟”,并为我正在监控的位置添加了一些 .gpx 文件。我设置了默认位置。
当我启动时,我的位置管理器委托被调用。我在模拟器中获得 .authorizedWhenInUse,在手机上获得 .authorizedAlways。
locationManager(:didUpdateLocations:) 在位置改变时被调用。
-
调用 didUpdateLocations 时,我执行以下操作:
for r in manager.monitoredRegions { if let cr = r as? CLCircularRegion { if cr.contains(location.coordinate) { log.debug("Am in the region!") } else { let crLoc = CLLocation(latitude: cr.center.latitude, longitude: cr.center.longitude) log.debug("distance is: \(location.distance(from: crLoc))") } }它有效。所以我的地区正在被监控,我的位置是我认为应该在的地方。
最后,我的 locationManager 委托的 monitoringDidFailFor 和 didFailWithError 没有被调用。并不是说他们从来没有 - 他们在开发期间有过,但现在没有。
所以我很难过。同样,它在手机上运行良好,而不是在模拟器中运行良好。
我做错了什么?
【问题讨论】:
标签: ios swift xcode ios-simulator cllocationmanager