标签:
本地通知使用注意:用户使用当前app的时候时接收不到这个app的通知的,app必须在后台或者结束才能发送通知
下面是一个简单的本地通知例子
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
- ( void )viewDidLoad { [ super viewDidLoad]; [ self localNotify]; //把应用右上角提醒数字设置为0 [[UIApplication sharedApplication] setApplicationIconBadgeNumber:0]; } - ( void )localNotify { //1.创建通知对象 UILocalNotification *localNotify = [[UILocalNotification alloc] init]; //设置通知内容 localNotify.alertBody = @ "这是一个本地通知" ; //锁屏状态下的通知内容 localNotify.alertAction = @ "锁屏状态通知" ; //设置通知时间 localNotify.fireDate = [ NSDate dateWithTimeIntervalSinceNow:8]; //重复多少个单元发送一次(一分钟发送一次,两天发送一次,一周发送一次) localNotify.repeatInterval = NSCalendarUnitMinute ; //应用图标右上角提醒数字 localNotify.applicationIconBadgeNumber = 5; //2.调度通知 UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert | UIUserNotificationTypeBadge categories: nil ]; [[UIApplication sharedApplication] registerUserNotificationSettings:settings]; [[UIApplication sharedApplication] scheduleLocalNotification:localNotify]; } |
标签:
原文地址:http://www.cnblogs.com/luoxiaofu/p/5220762.html