我正在开发一个应用程序,如果终止,它将无法工作。它有一些后台任务。如果应用程序终止,我想显示本地通知。有些应用程序可以做到这一点,这意味着这是可行的。但我无法找到方法。
我试图在 applicationWillTerminate: 方法的 appdelegate 中设置本地通知,并在我的视图控制器中添加了应用程序终止的通知,但是当应用程序实际终止时没有调用任何方法。
- (void)applicationWillTerminate:(UIApplication *)application
{
NSLog(@"terminated");
UIApplication * app = [UIApplication sharedApplication];
NSDate *date = [[NSDate date] dateByAddingTimeInterval:15];
UILocalNotification *alarm = [[UILocalNotification alloc] init] ;
if (alarm) {
alarm.fireDate = [NSDate date];
alarm.timeZone = [NSTimeZone defaultTimeZone];
alarm.repeatInterval = 0;
alarm.alertBody = @"This app does not work if terminated";
alarm.alertAction = @"Open";
[app scheduleLocalNotification:alarm];
}
[app presentLocalNotificationNow:alarm];
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}
任何帮助都会很棒。
提前致谢 !!!