我登錄(寫入文件),我的每一個應用程序從掛起模式喚醒的時間backgroundTimeRemaining值,之前,我開始的UIApplication的後臺任務與到期處理,像這樣(我的方法,這使得網絡請求中):爲什麼即使應用程序狀態爲UIApplicationStateBackground,backgroundTimeRemaining也會給出DBL_MAX?
當應用程序在前臺運行,在此屬性 值保持適當大:
if([[UIApplication sharedApplication] applicationState] == UIApplicationStateBackground){ [Logger logIntoFileNamed:@"log" withContent:[NSString stringWithFormat:@" state %ld, background time remaining %.2f",(long)[[UIApplication sharedApplication] applicationState],[[UIApplication sharedApplication] backgroundTimeRemaining ]] andPrettyTime:true]; UIApplication* app = [UIApplication sharedApplication]; __block UIBackgroundTaskIdentifier task = [app beginBackgroundTaskWithExpirationHandler:^{ [app endBackgroundTask:task]; task = UIBackgroundTaskInvalid; [Logger logIntoFileNamed:@"log" withContent:@" expiration handler executed " andPrettyTime:true]; }]; }
根據文檔的
backgroundTimeRemaining
一個值,如果應用程序是在前臺大。
但這不是這裏的情況。由於應用程序狀態等於UIApplicationStateBackground
,因此執行我的方法。 我在這裏錯過了什麼?
剛剛檢查...我實際上'線程1'發生這種情況時。這應該是主線程(當我從'applicationDidEnterBackground'運行這段代碼時:'它說'線程5')。事情是,我不是編寫代碼這部分的人,我想,因爲我確信應用程序是從掛起模式喚醒的事實,我目前正在執行所有這些操作。 ..有更多的調查和代碼,但如果我在主線程,那麼我得到正常的結果,對吧? – Whirlwind