2010-12-03 70 views
0

在我的應用程序中,我使用CLLocationManager和AdWhirl。我沒有針對背景模式進行特定開發:我不希望我的應用程序在後臺工作,即當用戶按下「home button」時,GPS位置不應該更新iphone:位置管理器+ adwhirl =電池耗盡:(

昨天傍晚我按下了「home button」,今天早上iPhone已經沒電了,這是一款iOS 4.1的iPhone 4,不是jailbreaked,並沒有後臺程序運行。

電池約爲35%,昨天晚上,和0%,今早(iPhone被關閉)。

我在我的委託中設置了斷點,每次GPS位置更新時都會調用斷點。當應用程序處於後臺模式時,不會調用委託。所以我認爲GPS在後臺模式下真的被禁用:好的。

今天早上,我跟着電量消耗:每15分鐘大約減少1%。我覺得有點太過分了。

我應該在應用程序轉到後臺模式時執行特定的操作嗎?你認爲這1%的下降是正常的嗎?

回答

0

是的,互聯網接入和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,都是在App Delegate中聲明的,我發現通過我在App Delegate中進行的所有位置管理更加有用。)

相關問題