2015-10-18 67 views
0

我希望能夠發送多個本地通知全天,這也必須在後臺模式下工作,它必須工作在一個計時器,所以每20分鐘精確。我遇到的問題是,一旦在後臺模式下,它們不會觸發,因爲用於設置定時器的函數將不會運行。發送本地通知,當應用程序處於後臺模式不起作用

我曾經想過在applicationDidEnterBackground中運行定時器,但是這會與函數中設置的原始定時器衝突。

反正基本上有這個工作嗎?任何智慧都會非常感激。

回答

0

嘗試尋找這link並藉此在你的任務在後臺

- (void)applicationDidEnterBackground:(UIApplication *)application 
{ 
    bgTask = [application beginBackgroundTaskWithName:@"MyTask" expirationHandler:^{ 
     // Clean up any unfinished task business by marking where you 
     // stopped or ending the task outright. 
     [application endBackgroundTask:bgTask]; 
     bgTask = UIBackgroundTaskInvalid; 
    }]; 

    // Start the long-running task and return immediately. 
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ 

     // Do the work associated with the task, preferably in chunks. 

     [application endBackgroundTask:bgTask]; 
     bgTask = UIBackgroundTaskInvalid; 
    }); 
} 
+0

這是客觀的C,我在工作迅速... –

相關問題