基本属性

本地通知的基本使用

  • 创建本地通知
  • 设置属性
  • 调度通知(添加通知到本地通知调度池)
  • 注册用户通知权限(只需一次, 可以单独放在Appdelegate中, 或者别的地方) —> iOS8以后必须, 需要用户授权才可以发送通知

   

 1 //1. 创建本地通知对象
 2         UILocalNotification *localNotifi = [UILocalNotification new];
 3         
 4         //2. 设置属性
 5         
 6         //2.1 设置触发时间
 7         localNotifi.fireDate = [NSDate dateWithTimeIntervalSinceNow:3];
 8         
 9         //2.2 设置提示内容
10         localNotifi.alertBody = @"我是通知";
11         
12         //2.3 设置声音 (只有真机有效)
13         localNotifi.soundName = UILocalNotificationDefaultSoundName;
14         
15         localNotifi.applicationIconBadgeNumber = 5;
16         
17         //2.4 设置 默认YES
18         localNotifi.hasAction = NO;
19         
20         //2.5 设置 提醒样式的按钮文字 / 锁屏界面底部的文字
21         localNotifi.alertAction = @"通知";
22         
23         // 将通知加入到本地调度池中
24         [[UIApplication sharedApplication] scheduleLocalNotification:localNotifi];
25         
26         // 注册通知设置
27         UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert categories:nil];
28             [[UIApplication sharedApplication] registerUserNotificationSettings:settings];

原文地址:https://www.cnblogs.com/SmileCCBoy/p/iOS.html