iOS 本地推送 UILocalNotification
来源:互联网 发布:nginx laravel 编辑:程序博客网 时间:2024/06/11 19:43
创建通知
- UILocalNotification *notification = [[UILocalNotification alloc] init];
- if (notification)
- {
- NSDate *now = [NSDate new];
- notification.fireDate = [now dateByAddingTimeInterval:10]; //10秒后通知
- notification.repeatInterval=0; //重复次数,kCFCalendarUnitWeekday一周一次
- notification.timeZone = [NSTimeZone defaultTimeZone]; //设置时区
- notification.applicationIconBadgeNumber = 1; //应用的角标
- notification.soundName = UILocalNotificationDefaultSoundName; //声音,可以换成alarm.soundName = @"sound.wav"
- //去掉下面2行就不会弹出提示框
- notification.alertBody = @"通知内容"; //提示信息 弹出提示框
- notification.alertAction = @"打开"; //提示框按钮
- //notification.hasAction = NO; //是否显示额外的按钮,为no时alertAction消失
- NSDictionary *infoDict = [NSDictionary dictionaryWithObject:@"value" forKey:@"key"];
- //设置userinfo 方便在之后需要撤销的时候使用 也可以传递其他值,当通知触发时可以获取
- notification.userInfo = infoDict;
- [[UIApplication sharedApplication] scheduleLocalNotification:notification];
- }
推送的内容
- //推送的内容
- - (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification*)notification
- {
- //这里,你就可以通过notification的useinfo,干一些你想做的事情了
- if ([[notification.userInfo objectForKey:@"key"] isEqualToString:@"value"])
- {
- UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"系统提示" message:@"你的系统存在严重威胁" delegate:nil cancelButtonTitle:@"关闭" otherButtonTitles:nil,nil];
- [alert show];
- }
- application.applicationIconBadgeNumber = 0; //移除角标
- }
- - (void)applicationDidBecomeActive:(UIApplication *)application
- {
- //不通过推送 通过应用图标打开应用 移除角标
- application.applicationIconBadgeNumber = 0;
- }
取消通知
- //获取当前所有的本地通知
- NSArray *notificaitons = [[UIApplication sharedApplication] scheduledLocalNotifications];
- if (!notificaitons || notificaitons.count <= 0)
- {
- return;
- }
- //取消一个特定的通知
- for (UILocalNotification *notify in notificaitons)
- {
- if ([[notify.userInfo objectForKey:@"key"] isEqualToString:@"value"])
- {
- [[UIApplication sharedApplication] cancelLocalNotification:notify];
- break;
- }
- }
- // //取消所有的本地通知
- // [[UIApplication sharedApplication] cancelAllLocalNotifications];
0 0
- iOS 本地推送 UILocalNotification
- iOS 本地推送 UILocalNotification
- ios推送:本地通知UILocalNotification
- ios推送:本地通知UILocalNotification
- ios推送:本地通知UILocalNotification
- ios推送:本地通知UILocalNotification
- ios推送:本地通知UILocalNotification
- iOS 本地推送通知 UILocalNotification
- ios推送:本地通知UILocalNotification
- iOS推送:本地通知UILocalNotification
- iOS推送:本地通知UILocalNotification
- iOS推送:本地通知UILocalNotification
- iOS本地推送UILocalNotification详解
- iOS --- 本地推送通知 UILocalNotification
- iOS推送:本地通知UILocalNotification
- iOS推送:本地通知UILocalNotification
- iOS本地通知推送使用:UILocalNotification
- iOS推送 之 本地通知UILocalNotification
- Android判断软键盘显示状态并隐藏
- oracle 查询最近执行过的 SQL语句
- c#学习之三:抽象类,密封类和类成员
- spring mvc 注解参数详解@
- Fragment的陷阱
- iOS 本地推送 UILocalNotification
- 【JQuery】:first和:last过滤选择器
- 双链表相比单链表的优点
- 双向链表 PushBack/PopFront
- Linux下.ko, .o, .so, .a, .la文件
- "The repository is locked."使用bitbucket出现的问题
- java 调用webservice的各种方法总结
- 真机调试出现:The identity used to sign the executable is no longer valid
- 手动创建一个小于10M的类嵌入式linux系统