如何解决如何测试iOS的后台位置更新?
我有一个应用程序,它要求用户在后台定位以触发某些事件和通知,类似于life360;如果用户终止了该应用,则后台位置更新仍应发生。
我的清单:
<key>UIBackgroundModes</key>
<array>
<string>fetch</string>
<string>location</string>
<string>processing</string>
<string>remote-notification</string>
</array>
在收到“始终”位置许可后,我已经像这样配置了CLLocationManager:
locationManager = CLLocationManager()
locationManager.delegate = self
locationManager.allowsBackgroundLocationUpdates = true
locationManager.pausesLocationUpdatesAutomatically = false
locationManager.distanceFilter = kCLDistanceFilterNone //meters
locationManager.desiredAccuracy = kCLLocationAccuracyBest
locationManager.startUpdatingLocation()
locationManager.desiredAccuracy = kCLLocationAccuracyBest
locationManager.startMonitoringSignificantLocationChanges()
locationManager.startMonitoringVisits()
并且我已经设置了willFinishLaunching函数,以测试位置更改后是否会召唤我的应用程序:
func application(_ application: UIApplication,willFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
if launchOptions?[UIApplication.LaunchOptionsKey.location] != nil {
// App launched from the background due to location change
UserDefaults.standard.set("Background Update Received",forKey: "locationUpdate")
}
return true
}
在过去的几个小时里,我的应用在尝试触发位置更新时终止了在城市中的行驶,但从未发生过。我的iPhone启用了后台应用刷新功能,并且“始终”具有位置权限。我看到这个过程很繁琐而且非常耗时。
我错过了什么吗?有没有比整日浪费汽油的方法更好的测试方法了?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。