2016-04-22 36 views
0

一般來說,如果我打開應用並鎖定屏幕,一個小時左右後如果我解鎖屏幕,應用會重新啓動。但我的應用程序無法重新啓動或恢復。有沒有任何設置來恢復我的應用程序,或者我錯過了什麼?iOS應用在解鎖屏幕後不能恢復

if (!oprationQueue) {// Application did enter in background method 
     oprationQueue = [[NSOperationQueue alloc] init]; 
    } 
    NSInteger updateSec = [[NH_Fetch_settings alloc] getUpdateTimeInterva]; 
    bgdataUpdateTimer = [NSTimer scheduledTimerWithTimeInterval:updateSec target:self selector:@selector(updateData:) userInfo:nil repeats:YES]; 
    NSInteger cleanSec = [[NH_Fetch_settings alloc] cleanupFrequency]; 
    bgCleanupTimer = [NSTimer scheduledTimerWithTimeInterval:cleanSec target:self selector:@selector(cleapAllData:) userInfo:nil repeats:YES]; 

    [NH_advertisement sharedInstance].isFirstTime = NO; 
    [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"advFirst"]; 


    backgroundTask_dataUpdate =[[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:^{ 

     NSLog(@"%f",[UIApplication sharedApplication].backgroundTimeRemaining); 
    }]; 

    backgroundTask_cleanUp =[[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:^{ 

     NSLog(@"%f",[UIApplication sharedApplication].backgroundTimeRemaining); 

    }];  
} 

- (void)applicationWillEnterForeground:(UIApplication *)application{ 
    [application endBackgroundTask:backgroundTask_dataUpdate]; 
    backgroundTask_dataUpdate = UIBackgroundTaskInvalid; 
    [application endBackgroundTask:backgroundTask_cleanUp]; 
    backgroundTask_cleanUp = UIBackgroundTaskInvalid; 

} 

該應用程序在解鎖屏幕後不會拋出resume事件。 該加油日誌屏幕上

的UIApplication _handleNonLaunchSpecificActions:forScene:withTransitionContext:完成:] **未處理的動作 - > { 處理機=遠程; info = { (1)= 5; }; }

+0

請確保您已在應用目標的「功能」選項卡中啓用了「背景模式」。 –

+0

先生,我相信我啓用後臺模式的能力 –

+0

你有初始化'NSOperationQueue'但沒有使用...爲什麼? –

回答

0

你可以做你通過所需的方法的AppDelgate

- (void)applicationWillResignActive:(UIApplication *)application; 
- (void)applicationDidEnterBackground:(UIApplication *)application; 
- (void)applicationWillEnterForeground:(UIApplication *)application; 
- (void)applicationDidBecomeActive:(UIApplication *)application; 

執行代碼如下方法要求什麼。

編輯:

正如你說,你的應用程序沒有恢復或解鎖iphone後重新啓動。

重新啓動的第一件事意味着AppDelegateapplication:didFinishLaunchingWithOptions被調用,但在您的情況下(在解鎖設備後,此方法不會被調用,即應用程序在此情況下不會重新啓動)。

要恢復應用程序的任務,您可以在applicationWillEnterForeground:applicationDidBecomeActive:中編寫代碼,並且您的編寫正確。

+0

我已經在所有App委託方法中編寫代碼..但是我的應用程序在解鎖屏幕後不能恢復...: (幫我 –

+0

分享你的代碼...所以人們可以幫助你 –

+0

先生..我更新代碼.. –

0

當你有鎖設備可能會執行一些代碼,可能會導致應用程序崩潰。請按照簡單的步驟在鎖定屏幕期間識別崩潰。嘗試查看應用程序遺留在設備上的任何崩潰日誌。

Connect your device 
Open XCode 
Go to the Organizer (Window > Organizer) 
Expand your device listing in the sidebar and select Device Logs 
Look for any crash logs left behind by your app 

而且還告訴我你是否有以下方法中的任何代碼。

- (void)applicationWillResignActive:(UIApplication *)application; 
- (void)applicationDidEnterBackground:(UIApplication *)application; 
- (void)applicationWillEnterForeground:(UIApplication *)application; 
- (void)applicationDidBecomeActive:(UIApplication *)application; 
+0

先生我更新代碼...請幫助我:( –

+0

這來在日誌屏幕........ UIApplication _handleNonLaunchSpecificActions:forScene:withTransitionContext:完成:] **未處理的行動 - > { 處理機=遠程; 信息= { (1)= 5; }; } –

+0

這意味着你有嘗試訪問私有方法,但這個類的實例不存在 – iMHitesh

0

我想你應該在beginBackgroundTaskWithExpirationHandler:^ {}方法中添加下面提到的代碼。

[application endBackgroundTask:backgroundTask_dataUpdate]; 
backgroundTask_dataUpdate = UIBackgroundTaskInvalid; 

所以代碼應該看起來像這樣。

backgroundTask_dataUpdate =[[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:^{ 

[application endBackgroundTask:backgroundTask_dataUpdate]; 
backgroundTask_dataUpdate = UIBackgroundTaskInvalid; 

NSLog(@"%f",[UIApplication sharedApplication].backgroundTimeRemaining); 
}]; 

注:以beginBackgroundTaskWithExpirationHandler每個呼叫必須有endBackgroundTask呼叫,否則OS可能會殺死你的應用程序。

+0

我在applicationWilEnterInForeground中添加了end backgroundTask .... Sir –

+0

UIApplication _handleNonLaunchSpecificActions:forScene:withTransitionContext:completion:] ** unhandled action - > { handler = remote;info = { (1)= 5; }; } –

+0

這在日誌屏幕上 –

相關問題