后台位置更新
目前,在我的应用程序中,这就是我当前所做的:
- 当用户触发时,ViewController-A (VC-A) 开始使用 startUpdatingLocation 或 startMonitoringForRegion 监视用户的 GPS 位置,具体取决于手机型号
- VC-A 也是CLLocationManager 的委托
- 目前,监控发生在前台 - 即应用程序必须正在运行。
为了在后台获取位置更新,这是我到目前为止所阅读和理解的内容……
- 将 CLLocationManager 委托方法信息分离为 newClass 并在 newClass VC-A 中实现委托方法,
- 启动监视
- 然后应使用 newClass 的实例在 newClass 接收更新时以及当条件是我通知用户时 , - 如果应用程序位于后台,则发送 localNotification;如果应用程序位于前台,则播放警报声音 - 停止监控
我需要在 AppDelegate.m 文件中执行任何特殊操作吗?
问候。
Currently, in my app, this is what I currently do:
- When the user triggers, ViewController-A (VC-A) startsMonitoring for GPS location of the user using either startUpdatingLocation or startMonitoringForRegion depending on the phone-model
- VC-A is also the delegate for CLLocationManager
- Currently, the monitoring happens in foreground - i.e. the app has to be running.
In order to get the location updates in background, this is what I have read and understood so far….
- separate the CLLocationManager delegate methods info a newClass and implement the delegate methods in the newClass
- VC-A then should use an instance of newClass to initiate the monitoring
- when newClass receives update and when the condition is me to notify the user,
- send localNotification if app is in background or play alertSound if app is in foreground
- stop monitoring
Do I need to do anything special in AppDelegate.m file?
Regards.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当您的应用程序进入后台时,您需要处理回调。我从你的问题假设你正在对当前设备进行区域监控,并且只是计算出旧设备的位置详细信息?
如果是这种情况,您需要在 AppDel 中实现 locationManager 并处理 -didEnterRegion 和 -didExitRegion 的回调以及 -significantLocationChange 回调的回调。
我刚刚实现了一个非常相似的设置(但我放弃了旧设备)。关键是在 AppDel 内部创建一个 locationManager 来处理回调。
如果您的应用程序位于前台,则用于创建区域或监视位置的 locationManager 可以正常工作。但是一旦你进入后台,你需要触发 -monitorForSignificantLocationChange 来保存电池并处理它的任何回调。
You need to handle the callbacks when your app goes into the background. I'm assuming from your question you are doing region monitoring for current devices, and just working out the location details for older devices?
If this is the case, you need to implement a locationManager in your AppDel as well as handling the callbacks for -didEnterRegion and -didExitRegion as well as the callbacks for the -significantLocationChange callbacks.
I just implemented a setup very similar (but I bailed on older devices). The key is creating a locationManager inside the AppDel to handle the callbacks.
If your app is in the foreground, the locationManager you use to create the regions or monitor location work just fine. But once you hit the background, you need to trigger the -monitorForSignificantLocationChange to save batter and handle any callbacks for it.