添加此段代碼后,程序進(jìn)入后臺(tái)10分鐘內(nèi)會(huì)響應(yīng) applicationWillTerminate 函數(shù),可以在其中添加保存或者清理工作。
// &&**&& 本地通知 kill 后 也是可以通知的
// 創(chuàng)建一個(gè)本地推送
UILocalNotification *notification = [[UILocalNotification alloc] init];
//設(shè)置10秒之后
NSDate *pushDate = [NSDate dateWithTimeIntervalSinceNow:10];
if (notification != nil) {
// 設(shè)置推送時(shí)間
notification.fireDate = pushDate;
// 設(shè)置時(shí)區(qū)
notification.timeZone = [NSTimeZone defaultTimeZone];
// 設(shè)置重復(fù)間隔
notification.repeatInterval = kCFCalendarUnitMinute;
// 推送聲音
notification.soundName = UILocalNotificationDefaultSoundName;
// 推送內(nèi)容
notification.alertBody = @"推送內(nèi)容";
//顯示在icon上的紅色圈中的數(shù)子
notification.applicationIconBadgeNumber += 1;
//設(shè)置userinfo 方便在之后需要撤銷的時(shí)候使用
NSDictionary *info = [NSDictionary dictionaryWithObject:@"name"forKey:@"key"];
notification.userInfo = info;
//添加推送到UIApplication
UIApplication *app = [UIApplication sharedApplication];
[app scheduleLocalNotification:notification];
}