iPhone:位置管理器 + adwhirl = 电池耗尽:(

发布于 2024-10-06 00:09:01 字数 415 浏览 0 评论 0原文

在我的应用程序中,我使用 CLLocationManager 和 AdWhirl。我没有对后台模式进行具体开发:我不希望我的应用程序在后台运行,即当用户按下“主页按钮”时,GPS 位置不应更新。

昨天晚上我按下“主页按钮”,今天早上 iPhone 没电了。这是一台装有 iOS 4.1 的 iPhone 4,未越狱,并且没有运行后台应用程序。

昨天晚上电池电量约为 35%,今天早上电量为 0%(iPhone 已关机)。

我在代理中设置了断点,每次更新 GPS 位置时都会调用该断点。当应用程序处于后台模式时,不会调用委托。所以我认为 GPS 在后台模式下确实被禁用了:好吧。

今天早上,我跟踪电池消耗情况:每 15 分钟大约下降 1%。我觉得有点太多了。

当应用程序进入后台模式时,我应该做一些特定的事情吗?你觉得这1%的下降正常吗?

In my app I am using CLLocationManager and AdWhirl. I have made no specific development regarding background mode: I don't want my app to be working when it is in background, i.e. when the user press the "home button", GPS location should no be updated.

Yesterday evening I pressed "home button", and this morning the iPhone was out of battery. It's an iPhone 4 with iOS 4.1, not jailbreaked, and there is no background app running.

The battery was about 35% yesterday evening, and 0% this morning (iPhone was shutdown).

I have set breakpoint in my delegate, which is called each time GPS location is updated. When app is in background mode, delegate is not called. So I'm thinking GPS is really disabled in background mode: ok.

This morning, I am following battery drain: it's about 1% drop each 15 min. I think it a bit too much.

Should I do something specific when the app goes to background mode? Do you think this 1% drop is normal?

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

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

发布评论

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

评论(1

过期情话 2024-10-13 00:09:01

是的,互联网接入和 GPS 是电池的两大消耗。我根本不知道你所说的正常是什么意思,因为没有其他应用程序正在运行,你已经得出结论,这实际上就是发生的情况:)假设你已经在没有运行任何应用程序的情况下进行了测试,并且每 15 没有获得 1%分钟...

对于 adwhirl,当应用程序进入后台时,尚不清楚它是否已经停止访问互联网,但您可以将其添加到您的应用程序委托中:

- (void)applicationDidEnterBackground:(UIApplication *)application {
    /*
     Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 
     If your application supports background execution, called instead of applicationWillTerminate: when the user quits.
     */
    [lm stopUpdatingLocation];
    [adView ignoreAutoRefreshTimer]
}


- (void)applicationWillEnterForeground:(UIApplication *)application {
    /*
     Called as part of  transition from the background to the active state: here you can undo many of the changes made on entering the background.
     */
    [adView doNotIgnoreAutoRefreshTimer]
    [lm startUpdatingLocation];
}

(lm 和 adView 是位置管理器对象和 adWhirlView,两者都在我发现通过我在应用程序代理中创建的方法进行所有位置管理更有用。)

Yes, internet access and GPS are two big drains on battery. I don't know at all what you mean with normal, since no other apps are running you've concluded that that is in fact what happens :) Assuming you've tested with NO apps running and didn't get 1% per 15 minutes...

For adwhirl, it's unknown whether it already stops accessing the internet when the app goes into the background, but you can add this to your App Delegate:

- (void)applicationDidEnterBackground:(UIApplication *)application {
    /*
     Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 
     If your application supports background execution, called instead of applicationWillTerminate: when the user quits.
     */
    [lm stopUpdatingLocation];
    [adView ignoreAutoRefreshTimer]
}


- (void)applicationWillEnterForeground:(UIApplication *)application {
    /*
     Called as part of  transition from the background to the active state: here you can undo many of the changes made on entering the background.
     */
    [adView doNotIgnoreAutoRefreshTimer]
    [lm startUpdatingLocation];
}

(lm and adView are the Location Manager object and the adWhirlView, both declared in the App Delegate. I've found it more useful to do all location managing via methods I make in the App Delegate.)

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