當後臺任務即將過期時,iOS應用程序可以調度本地通知嗎? 基本上我有一些服務器端正在進行下載,當應用程序進入後臺使用NSOperationQueue。
我想要的是當本地通知後臺任務即將完成時通知用戶。因此,該用戶可以將應用程序前臺,以保持服務器數據的持續下載
下面是我正在使用的代碼,但我沒有看到任何本地通知後臺任務即將到期時的本地通知
UIBackgroundTaskIdentifier bgTask = [application beginBackgroundTaskWithExpirationHandler: ^{
dispatch_async(dispatch_get_main_queue(), ^{
/*TO DO
prompt the user if they want to continue syncing through push notifications. This will get the user to essentially wake the app so that sync can continue.
*/
// create the notification and then set it's parameters
UILocalNotification *beginNotification = [[[UILocalNotification alloc] init] autorelease];
if (beginNotification) {
beginNotification.fireDate = [NSDate date];
beginNotification.timeZone = [NSTimeZone defaultTimeZone];
beginNotification.repeatInterval = 0;
beginNotification.alertBody = @"App is about to exit .Please bring app to background to continue dowloading";
beginNotification.soundName = UILocalNotificationDefaultSoundName;
// this will schedule the notification to fire at the fire date
//[app scheduleLocalNotification:notification];
// this will fire the notification right away, it will still also fire at the date we set
[application scheduleLocalNotification:beginNotification];
}
[application endBackgroundTask:self->bgTask];
self->bgTask = UIBackgroundTaskInvalid;
});
}];
你能解決這個問題嗎?我的意思是從後臺安排本地通知? – 2014-03-01 10:54:07