本地通知的实现
2016-01-02 23:14
260 查看
- (IBAction)openLocal:(id)sender {
UILocalNotification *ln = [[UILocalNotification alloc] init];
ln.alertAction = @"赶集赶紧";
ln.alertBody = @"我是本地通知";
ln.fireDate = [NSDate dateWithTimeIntervalSinceNow:5];
ln.timeZone = [NSTimeZone defaultTimeZone];
ln.repeatInterval = kCFCalendarUnitSecond;
ln.applicationIconBadgeNumber = 2;
ln.userInfo = @{@"key":@"go to study iOS"};
if ([[UIApplication sharedApplication] respondsToSelector:@selector(registerUserNotificationSettings:)]) {
UIUserNotificationType type = UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | UIUserNotificationTypeSound;
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:type categories:nil];
[[UIApplication sharedApplication] registerUserNotificationSettings:settings];
} else {
}
[[UIApplication sharedApplication] scheduleLocalNotification:ln];
}
- (IBAction)removeLocal:(id)sender {
[[UIApplication sharedApplication] cancelAllLocalNotifications];
NSLog(@"%@" , [UIApplication sharedApplication].scheduledLocalNotifications);
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
{
NSLog(@"我收到本地通知了");
NSString *message = notification.userInfo[@"key"];
NSLog(@"%@" , message);
NSInteger badge = [UIApplication sharedApplication].applicationIconBadgeNumber;
badge --;
badge = badge >= 0 ? badge : 0;
[UIApplication sharedApplication].applicationIconBadgeNumber = badge;
}
UILocalNotification *ln = [[UILocalNotification alloc] init];
ln.alertAction = @"赶集赶紧";
ln.alertBody = @"我是本地通知";
ln.fireDate = [NSDate dateWithTimeIntervalSinceNow:5];
ln.timeZone = [NSTimeZone defaultTimeZone];
ln.repeatInterval = kCFCalendarUnitSecond;
ln.applicationIconBadgeNumber = 2;
ln.userInfo = @{@"key":@"go to study iOS"};
if ([[UIApplication sharedApplication] respondsToSelector:@selector(registerUserNotificationSettings:)]) {
UIUserNotificationType type = UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | UIUserNotificationTypeSound;
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:type categories:nil];
[[UIApplication sharedApplication] registerUserNotificationSettings:settings];
} else {
}
[[UIApplication sharedApplication] scheduleLocalNotification:ln];
}
- (IBAction)removeLocal:(id)sender {
[[UIApplication sharedApplication] cancelAllLocalNotifications];
NSLog(@"%@" , [UIApplication sharedApplication].scheduledLocalNotifications);
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
{
NSLog(@"我收到本地通知了");
NSString *message = notification.userInfo[@"key"];
NSLog(@"%@" , message);
NSInteger badge = [UIApplication sharedApplication].applicationIconBadgeNumber;
badge --;
badge = badge >= 0 ? badge : 0;
[UIApplication sharedApplication].applicationIconBadgeNumber = badge;
}
相关文章推荐
- Hbase设置Snappy压缩测试
- IO流
- 从头认识java-15.7 Map(5)-介绍HashMap的工作原理-Key变了,能不能get出原来的value?(偶尔作为面试题)
- 我的博客
- 磁力计的基本工作原理
- 【u3d】环境搭建
- 关于开源框架SuperRecyclerView瀑布流卡顿问题
- scrollerView 滚动的时候改变 scrollerView 的背景色代码
- 邮件服务器 Exchange2010视频教程(精品珍藏版)
- LIBSVM学习——文本分类
- IntelliJ IDEA 常用设置讲解
- 学习笔记(二)——直方图均衡化和匹配
- 立体像对DEM提取
- Intent重点小结
- Eclipse常用的快捷键大全
- 【iOS9系列】-3DTouch开发
- 学习笔记(一)——图像的灰度级和动态范围
- 天天模拟器 和 Genymotion 设置代理
- LeetCode307. Range Sum Query - Mutable二叉索引树实战
- JS 鼠标滚轮事件(mousewheel/DOMMouseScroll)