iPhone-在背景模式下停用cllocationmanager事件

发布于 2024-12-05 06:44:22 字数 383 浏览 1 评论 0原文

我有一个使用 CLLocationManager 接收位置和航向更新的应用程序。当应用程序发送到后台模式时,CLLocationManager 仍然接收事件(当应用程序不在屏幕上时在调试器中捕获)。

我是否有义务捕获“发送到后台”事件并使用 BOOL 退出事件委托方法以忘记这些更新,或停止/重新启动 CLLocationManager ?

或者是否有另一种解决方案可以在后台停止接收这些事件?

我想防止这种情况发生,不要执行无用的操作,并可能减少电池电量,因为我不需要这些事件。

我知道有一个 project.plist 参数可以设置为强制 iOS 继续向应用程序发送位置事件,即使它在后台也是如此。我没有设置该参数。所以我想有一种方法可以告诉iOS我不想在后台发生这些事件......

I have an app that uses the CLLocationManager to receive location and heading updates. When the app in sent to background mode, the CLLocationManager still receive events (catched in the debugger while the app is not onscreen).

Am I obliged to trap the "sent to background" event and use a BOOL to exit the event delegate method to forget those updates, or stop/restart the CLLocationManager ?

or is there another solution to stop receiving those events when in background ?

I'd like to prevent this not to do useless actions, and possibly reduce battery, as I don't need those events.

I know there is a project.plist param to set to force iOS to continue sending location events to the app even if it's in background. I didn't set that parameter. So I guess there is a way to tell iOS that I don't want those events when in background...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

友欢 2024-12-12 06:44:22

使用 UIApplicationDelegate 的以下方法:

-(void)applicationDidBecomeActive:(UIApplicetion*)application;
-(void)applicationWillResignActive:(UIApplicetion*)application;
-(void)applicationDidEnterBackground:(UIApplicetion*)application;
-(void)applicationWillEnterForeground:(UIApplicetion*)application;

Use next methods of UIApplicationDelegate:

-(void)applicationDidBecomeActive:(UIApplicetion*)application;
-(void)applicationWillResignActive:(UIApplicetion*)application;
-(void)applicationDidEnterBackground:(UIApplicetion*)application;
-(void)applicationWillEnterForeground:(UIApplicetion*)application;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文