1、增加一个本地推送
//设置20秒之后 

];

//chuagjian一个本地推送

UILocalNotification *noti =
[[[UILocalNotification alloc] init] autorelease];

if (noti) {

//设置推送时间

noti.fireDate = date;

//设置时区

noti.timeZone = [NSTimeZone defaultTimeZone];

//设置重复间隔

noti.repeatInterval = NSWeekCalendarUnit;

//推送声音

noti.soundName = UILocalNotificationDefaultSoundName;

//内容

noti.alertBody = @"推送内容";

//显示在icon上的红色圈中的数子

;

//设置userinfo 方便在之后需要撤销的时候使用

NSDictionary *infoDic = [NSDictionary dictionaryWithObject:@"name" forKey:@"key"];

noti.userInfo = infoDic;

//添加推送到uiapplication

UIApplication *app = [UIApplication sharedApplication];

[app scheduleLocalNotification:noti];

}

2、程序运行时接收到本地推送消息

- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification*)notification

{

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"接收到本地提醒 in
app"

message:notification.alertBody

delegate:nil

cancelButtonTitle:@"确定"

otherButtonTitles:nil];

[alert show];

//这里,你就可以通过notification的useinfo,干一些你想做的事情了

;

}

3、取消一个本地推送

UIApplication *app = [UIApplication sharedApplication];

//获取本地推送数组

NSArray *localArr = [app scheduledLocalNotifications];

//声明本地通知对象

UILocalNotification *localNoti;

if (localArr) {

for (UILocalNotification *noti in localArr) {

NSDictionary *dict = noti.userInfo;

if (dict) {

NSString *inKey = [dict objectForKey:@"key"];

if ([inKey isEqualToString:key]) {

if (localNoti){

[localNoti release];

localNoti = nil;

}

localNoti = [noti retain];

break;

}

}

}

//判断是否找到已经存在的相同key的推送

if (!localNoti) {

//不存在 初始化

localNoti = [[UILocalNotification alloc] init];

}

if (localNoti && !state) {

//不推送 取消推送

[app cancelLocalNotification:localNoti];

[localNoti release];

return;

}

}


  1. 第一步:创建本地推送
  2. // 创建一个本地推送
  3. UILocalNotification *notification = [[[UILocalNotification alloc] init] autorelease];
  4. //设置10秒之后
  5. ];
  6. if (notification != nil) {
  7. // 设置推送时间
  8. notification.fireDate = pushDate;
  9. // 设置时区
  10. notification.timeZone = [NSTimeZone defaultTimeZone];
  11. // 设置重复间隔
  12. notification.repeatInterval = kCFCalendarUnitDay;
  13. // 推送声音
  14. notification.soundName = UILocalNotificationDefaultSoundName;
  15. // 推送内容
  16. notification.alertBody = @"推送内容";
  17. //显示在icon上的红色圈中的数子
  18. ;
  19. //设置userinfo 方便在之后需要撤销的时候使用
  20. NSDictionary *info = [NSDictionary dictionaryWithObject:@"name"forKey:@"key"];
  21. notification.userInfo = info;
  22. //添加推送到UIApplication
  23. UIApplication *app = [UIApplication sharedApplication];
  24. [app scheduleLocalNotification:notification];
  25. }
  26. 第二步:接收本地推送
  27. - (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification*)notification{
  28. UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"iWeibo" message:notification.alertBody delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil];
  29. [alert show];
  30. // 图标上的数字减1
  31. ;
  32. }
  33. 第三步:解除本地推送
  34. // 获得 UIApplication
  35. UIApplication *app = [UIApplication sharedApplication];
  36. //获取本地推送数组
  37. NSArray *localArray = [app scheduledLocalNotifications];
  38. //声明本地通知对象
  39. UILocalNotification *localNotification;
  40. if (localArray) {
  41. for (UILocalNotification *noti in localArray) {
  42. NSDictionary *dict = noti.userInfo;
  43. if (dict) {
  44. NSString *inKey = [dict objectForKey:@"key"];
  45. if ([inKey isEqualToString:@"对应的key值"]) {
  46. if (localNotification){
  47. [localNotification release];
  48. localNotification = nil;
  49. }
  50. localNotification = [noti retain];
  51. break;
  52. }
  53. }
  54. }
  55. //判断是否找到已经存在的相同key的推送
  56. if (!localNotification) {
  57. //不存在初始化
  58. localNotification = [[UILocalNotification alloc] init];
  59. }
  60. if (localNotification) {
  61. //不推送 取消推送
  62. [app cancelLocalNotification:localNotification];
  63. [localNotification release];
  64. return;
  65. }
  66. }

本地通知UILocalNotification的更多相关文章

  1. IOS 本地通知 UILocalNotification

    IOS 本地通知 UILocalNotification [本文章第四部分中的代码逻辑来自网上的借鉴,并非我自己原创] 大概一个月前,我开始跟着做IOS项目了.学习C++,了解Objective-C, ...

  2. 本地通知-UILocalNotification

    第一步:创建本地推送 本地通知 UILocalNotification // 创建⼀一个本地推送 UILocalNotification * notification = [[UILocalNotif ...

  3. ios推送:本地通知UILocalNotification

    Notification是智能手机应用编程中非常常用的一种传递信息的机制,而且可以非常好的节省资源,不用消耗资源来不停地检查信息状态(Pooling),在iOS下应用分为两种不同的Notificati ...

  4. IOS 本地通知UILocalNotification

    //发送通知    UILocalNotification *notification=[[UILocalNotification alloc] init];       if (notificati ...

  5. iOS 注冊本地通知(推送)

    注:按Home键让App进入后台执行时.方可查看通知. - (BOOL)application:(UIApplication *)application didFinishLaunchingWithO ...

  6. iOS 进阶---推送通知之本地通知

    1.推送通知的2种方式 1)本地推送通知(Local Notification) 2)远程推送通知(Remote Notification) 2.通知的作用 可以让不在前台运行的app,告知用户app ...

  7. iOS开发本地通知

    /* 本地通知:不通过网络,在本地实现的通知,自己发给自己 远程通知:必须通过网络,使用推送技术(APNs),实现通知 本地通知: 1.要完成可以接收的通知形式的注册 2.具体通知的设置 3.发送通知 ...

  8. iOS10以前的本地通知和远程通知

    一.简介 分为本地推送和远程推送2种.可以在应用没有打开甚至手机锁屏情况下给用户以提示.它们都需要注册,注册后系统会弹出提示框(如下图)提示用户是否同意,如果同意则正常使用:如果用户不同意则下次打开程 ...

  9. UILocalNotification本地通知的使用方法

    本文所写方法主要应用UILocalNotification达到本地推送通知栏信息 取消了其他教程里过期的UIAlertView方法 使用UILocalNotification主要分为创建 调用 取消 ...

随机推荐

  1. 【BZOJ1996】合唱队(动态规划)

    [BZOJ1996]合唱队(动态规划) 题面 BZOJ 题解 很容易的一道题 因为每个人不是放在了左边就是放在了右边 所以每次放好的人必定是原序列的一个子串 所以,很容易想到区间\(dp\) 设\(f ...

  2. c++面试遇到问题

    1. C 和 C++ 区别      2. const 有什么用途     主要有三点: 1:定义只读变量,即常量 2:修饰函数的参数和函数的返回值 3: 修饰函数的定义体,这里的函数为类的成员函数, ...

  3. c++ STL容器适配器

    一.标准库顺序容器适配器的种类     标准库提供了三种顺序容器适配器:queue(FIFO队列).priority_queue(优先级队列).stack(栈)   二.什么是容器适配器     &q ...

  4. ssm实现分页查询

    ssm整合实现分页查询 一.通过limit查询语句实现分页,并展示 1.mapper.xml配置 <select id="selectUsersByPage" paramet ...

  5. MySQL单表百万数据记录分页性能优化,转载

    背景: 自己的一个网站,由于单表的数据记录高达了一百万条,造成数据访问很慢,Google分析的后台经常报告超时,尤其是页码大的页面更是慢的不行. 测试环境: 先让我们熟悉下基本的sql语句,来查看下我 ...

  6. imageview无法显示图片:java.lang.RuntimeException: Canvas: trying to draw too large(281520000bytes) bitmap

    图片太大需要压缩. 压缩方法:http://jingyan.baidu.com/article/cdddd41c3ef41153ca00e162.html 如果特别大(几十M),可以先用在线的图片压缩 ...

  7. syskey——让你的电脑更加安全

    我之前介绍过一个绕过系统登录密码的工具kon-boot,今天介绍的就是可以防止这个工具的方法,也能让你的电脑更加的安全. 这个方法也是我在Youtube上看见的一个方法,还是不错. 方法: win+R ...

  8. python全栈开发-Day5 元组、字典

    python全栈开发-Day5  元组.字典 一.前言 首先,不管学习什么数据类型,我们都带着以下几个问题展开学习: #1:基本使用 1 .用途 2 .定义方式 3.常用操作+内置的方法 #2:该类型 ...

  9. MySql (MariaDB)的varchar字段的存储的是字符还是字节

    关于varchar字段: 在version4之前,按字节: version5之后,按字符. 现在普遍都按字符算:无论中文英文,都算一个字符 既: varchar(10) == '123456789a' ...

  10. Maven-03: 优化依赖

    已解析依赖: Maven会自动解析项目的直接依赖和传递性依赖,并且根据规则正确判断每个依赖的范围,对于一些依赖冲突,也能进行调节,以确保任何一个构件只有唯一的版本在依赖中存在.在这些工作之后,最后得到 ...