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. 【BZOJ4010】【HNOI2015】菜肴制作(拓扑排序)

    [BZOJ4010][HNOI2015]菜肴制作(拓扑排序) 题面 Description 知名美食家小 A被邀请至ATM 大酒店,为其品评菜肴. ATM 酒店为小 A 准备了 N 道菜肴,酒店按照为 ...

  2. 误操作导致 lvdisplay 命令不存在解决

    1.lvdisplay 命令不存在 查看lvm2 包被卸载2.执行 yum install lvm2 命令 发现 yum 被锁 3.删除yum.lock 发现/ 目录只读4.mount -o remo ...

  3. eclipse 中启动Tomcat超时了错误

    修改E:\eclipse\eclipse\workspace\.metadata\.plugins\org.eclipse.wst.server.core\servers.xml 将 start-ti ...

  4. 找出k个数相加得n的所有组合

    Find all possible combinations of k positive numbers that add up to a number n,each combination shou ...

  5. 今天给大家分享用Python matplotlib来写随机漫步的小程序

    先安装两个库: pip install matplotlib pip install numpy 引用库: import matplotlib.pyplot as mp import numpy as ...

  6. IM-iOS退出后台接受消息,app退出后台能接收到推送

    App被失活状态的时候可以走苹果的APNS:但是在活跃的时候却接受不到推送! 那就用到本地推送:UILocalNotification 消息神器. 处理不好可能会有很多本地推送到来,那么问题来了要在什 ...

  7. emacs在windows下打开报错原因

    最开始实在是想不通,最开始我明明就能正常使用,后来发现不能用了,过了几天才回过神来,我路径中有中文,换了一个没有中文的路径后打开正常了.太低级的错误了嘛,却那么难发现. 这些数字就是识别不出来我的中文 ...

  8. 设计模式——建造者模式/生成器模式(C++实现)

    #include <iostream> #include <string> using namespace std; class STProduct { public: voi ...

  9. python虚拟环境介绍与安装

    视频链接:  http://edu.tv.sohu.com/play/sid/8fefb999e05c5b01 1.为什么安装虚拟环境? 因为python框架更新迭代太快,有时电脑上存在一个框架多个版 ...

  10. maven依赖大全

    1.oracle mysql驱动 <!-- mysql驱动支持 --> <dependency> <groupId>mysql</groupId> &l ...