有史以来最奇怪的事情:即使应用程序未运行,核心位置仍保持活动状态

发布于 2024-09-08 07:01:01 字数 633 浏览 4 评论 0原文

今天下午,我带着 iPhone 4 走进 Apple Store,看看他们是否可以帮助解决我一直遇到的问题。电池续航时间根本没有达到应有的水平——放在办公桌上一晚上电池电量下降了 50%。疯狂的。所以我怀疑我有一个流浪汉单位。发生了。没什么大不了的。

我友好的天才在我的手机上看了一会儿,并指出位置服务指针在屏幕右上角亮起。他进入位置服务设置。他指出,以下应用程序的“在过去几个小时内获取位置数据”标志亮起:天气频道、Showtimes 以及我编写的、距离提交还有几天的应用程序。

他关闭了每个应用程序的滑块,我们看到顶部角落的位置服务指针关闭。重新打开我的任何一个应用程序的位置服务都会使其重新打开,但天气频道或 Showtimes 的情况并非如此。但很明显,为我的两个应用程序打开位置服务会启动设备的位置服务。我糟糕的电池寿命得到了解释,但这只是谜团的开始。

事情是这样的……当时我的两个应用程序都没有运行。他们甚至没有背景。他们关了。我认为它们目前都内置在我设备上的调试配置文件中,并且它们都使用 Core Location。他们没有被暂停,他们只是平躺着,没有运行。然而,打开位置服务控制面板中的滑块通常会启动位置服务。

那么...这里到底发生了什么?这些应用程序都没有配置后台位置。而且......他们不在后台!由于我已经关闭了它们的定位服务,毫无疑问我的电池使用量大大降低了。

This afternoon I walked my iPhone 4 into the Apple Store to see if they could help with a problem I've been having. Battery life hasn't been AT ALL what it should be--the battery drops 50% sitting on my desk overnight. Crazy. So I suspect I've got a bum unit. Happens. No biggie.

My friendly genius pokes around my phone a bit, and points out that the Location Services pointer is lit in the top right corner of the screen. He gets into the location services settings. He notes that the following apps have the "got location data in the last few hours" flag lit: The Weather Channel, Showtimes, and two apps I wrote and am days away from submitting.

He turns off the sliders for each of those apps, and we see the top corner location services pointer turn off. Turning back on location services for EITHER of my apps makes it turn back on, and that's NOT the case for Weather Channel or Showtimes. But it's clear that turning on location services for my two apps fires up the device's location services. My lousy battery life is explained, but that's just the beginning of the mystery.

Here's the thing.... Neither of my apps are EVEN RUNNING at the time. They're not even backgrounded. They're OFF. I think they're both built in a debugging profile on my device at the moment, and they both do use Core Location. They're not suspended, they're just flat not running. And yet, turning on the slider in the location services control panel for either of them fires up location services in general.

So... What the heck is happening here? Neither of those apps are configured for background location. And... they're not IN the background! And since I've had location services turned off for them, there's no doubt my battery usage is way way down.

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

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

发布评论

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

评论(1

人生戏 2024-09-15 07:01:01

解决方案位于 Apple 开发者论坛的以下主题:https://devforums.apple。 com/thread/58063?tstart=0

这两个应用的早期版本都调用了 [locationManager startMonitoringSignificantLocationChanges],而从未调用过 stopMonitoring...。即使当前版本的应用程序没有进行该调用,操作系统仍然将监控请求“注册”到应用程序(事实上,当我在城镇里开车时,它在后台重新启动它们!)。

我不知道的是,监控请求在启动和重建过程中仍然存在!我假设,像 -startUpdatingLocation 一样,监视请求会随着进程而终止,但事实并非如此。解决方案是从我的设备中删除应用程序并重新安装。

The solution is at this thread in the Apple developer forum: https://devforums.apple.com/thread/58063?tstart=0

An earlier version of both of these apps had called [locationManager startMonitoringSignificantLocationChanges], and never called stopMonitoring.... Even though the current version of the apps didn't make that call, the OS still had the monitoring request "registered" to the apps (and was, in fact, relaunching them in the background as I drove around town!).

What I didn't know was that the monitoring request persists across launches--and across re-builds! I'd assumed that, like -startUpdatingLocation, the monitoring request would die with the process, but not so. The solution was to delete the apps from my device and reinstall.

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