バックグラウンド タスクの有効期限が切れようとしているときに、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;
});
}];