当后台任务即将到期时,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;
});
}];