本地通知实现步骤:
1> 在didFinishLaunchingWithOptions 提前注册通知类型 (iOS8以上就需要)
-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
UIUserNotificationType type = UIUserNotificationTypeBadge | UIUserNotificationTypeAlert | UIUserNotificationTypeSound;
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:type categories:nil];
[application registerUserNotificationSettings:settings];
return YES;
}
2> 创建本地通知–>设置通知其他属性 –> 注册通知
//创建本地通知
UILocalNotification *note = [[UILocalNotification alloc]init];
//设置属性
note.fireDate = [NSDate dateWithTimeIntervalSinceNow:5];
note.timeZone = [NSTimeZone defaultTimeZone];
note.applicationIconBadgeNumber = 888;
note.alertAction = @"这锁屏界面消息";
note.alertBody = @"通知内容";
//注册通知
UIApplication *application =[UIApplication sharedApplication];
[application scheduleLocalNotification:note];