ios - 如何测试后台位置更新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 具有后台应用刷新功能和“始终”位置权限。我已经看到这个过程很乏味并且非常耗时。
我错过了什么吗?有没有比整天开车浪费汽油更好的方法来测试这个?
解决方案
推荐阅读
- notepad++ - 如何在记事本++中查找所有不同的重复项并删除所有但仅保留一个
- python - 我正在尝试从 csv 转换为 json,它给出了一个错误,因为缺少值
- reactive-programming - 如何下载文件并立即流式传输 - 上传 - 使用 Spring Reactive WebClient
- linux - 作为 bindkey 函数的一部分,在 zsh 中手动调用 compinit
- python - Python lambda 函数改变它们的值
- excel - 格式化图表上的数据标签
- javascript - 如何禁用模板添加的按钮数组?
- c++ - C++ 的 spdlog;what():无法打开文件 ~/logs/log.txt 进行写入:没有这样的文件或目录
- function - flatMapMerge 缓存是否流动?
- c++ - 在 cmake 中使用 MinGW 构建 Assimp 时出现“未找到 LIB”错误