本地推送 UILocalNotification
来源:互联网 发布:护国神翼 知乎 编辑:程序博客网 时间:2024/06/17 01:05
初始化本地推送
- - (void)initLocationNotification
- {
- //初始化
- UILocalNotification *locationNotification = [[UILocalNotification alloc] init];
- //设置推送时间,这里使用相对时间,如果fireDate采用GTM标准时间,timeZone可以至nil
- locationNotification.fireDate = [NSDate dateWithTimeIntervalSinceNow:10];
- locationNotification.timeZone = [NSTimeZone defaultTimeZone];
- //设置重复周期
- locationNotification.repeatInterval = NSWeekCalendarUnit;
- //设置通知的音乐
- locationNotification.soundName = UILocalNotificationDefaultSoundName;
- //设置通知内容
- locationNotification.alertBody = @"推送测试--balabala";
- //设置程序的Icon数量
- locationNotification.applicationIconBadgeNumber = 1;
- //执行本地推送
- [[UIApplication sharedApplication] scheduleLocalNotification:locationNotification];
- }
本地推送执行时会调用UIApplication的协议方法
- - (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
在此方法中可以获取推送的内容
- - (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
- {
- NSLog(@"推送信息已经获得: %@",[notification alertBody]);
- UIAlertView *alert = [[[UIAlertView alloc] initWithTitle:nil message:[notification alertBody] delegate:self cancelButtonTitle:nil otherButtonTitles:@"good", nil] autorelease];
- [alert show];
- }
响应结果:
如果使用的是服务器推送,则会进入回调方法:
- - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
- 本地推送 UILocalNotification
- 本地推送 UILocalNotification
- 本地推送UILocalNotification
- 本地推送UILocalNotification
- 本地推送 UILocalNotification
- 本地推送UILocalNotification
- UILocalNotification本地推送机制
- 本地推送UILocalNotification
- 本地推送UILocalNotification
- iOS 本地推送 UILocalNotification
- UILocalNotification本地推送
- 本地推送UILocalNotification(整理)
- 本地推送UILocalNotification
- 本地推送通知UILocalNotification
- iOS 本地推送 UILocalNotification
- 本地推送UILocalNOtification整理
- 本地推送 UILocalNotification
- UILocalNotification本地推送
- Developing School's Contest 2012-2 by HUT :数字游戏续
- GDB调试
- 怎么在word里插入visio的图片呢??
- mips gdb调试发现
- Android提高第九篇之SQLite分页表格
- 本地推送 UILocalNotification
- Asp.Net+Jquery.Ajax详解1-开篇
- imx53 QSB添加模拟I2C
- 通过设置UIView得layer实现圆角矩形
- 如何在Tomcat或其他基于Java的Web服务器下安装SSL证书
- 数据类型转换
- 使用linux的五个理由
- 关于脚本
- oracle创建角色以及创建表