在我的应用中,我使用的是CllocationManager和AdWhirl。我没有对背景模式进行具体的开发:我不希望我的应用在背景时工作,即当用户按“主机按钮”时,不应更新GPS位置。

昨天晚上,我按下了“主页按钮”,今天早上,iPhone电池电量不足。这是带有iOS 4.1的iPhone 4,没有被越狱,也没有运行背景应用程序。

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

我已经在我的委托中设置了断点,这是每次更新GPS位置时称为。当应用处于后台模式时,未调用委托。因此,我认为GPS确实在背景模式下确实被禁用:确定。

今天早上,我正在关注电池耗尽:每15分钟下降约1%。我认为这太多了。

当应用进入后台模式时,我应该做一些特定的事情吗?您认为这1%的下降是正常的吗?

有帮助吗?

解决方案

是的,互联网访问和GPS是电池上的两个大排水管。我根本不知道您对正常的含义,因为没有其他应用程序正在运行,您得出的结论是实际上发生了什么:)假设您已经在没有应用程序运行的情况下测试过,并且每15%没有得到1%分钟...

对于AdWhirl,未知该应用程序进入后台时是否已经停止访问Internet,但是您可以将其添加到您的应用程序委托中:

- (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,均在应用程序委托中声明。我发现通过在应用程序委托中制作的方法进行所有位置管理更有用。)

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top