第一步:创建本地推送
// 创建一个本地推送
UILocalNotification *notification = [[[UILocalNotification alloc]
init] autorelease];
//设置10秒之后
NSDate *pushDate = [NSDate dateWithTimeIntervalSinceNow:10];

if (notification != nil) {
    //
设置推送时间
   
notification.fireDate = pushDate;
    //
设置时区
   
notification.timeZone = [NSTimeZone defaultTimeZone];
    //
设置重复间隔
   
notification.repeatInterval = kCFCalendarUnitDay;
    //
推送声音
   
notification.soundName = UILocalNotificationDefaultSoundName;
    //
推送内容
   
notification.alertBody = @"推送内容";
   
//显示在icon上的红色圈中的数子
   
notification.applicationIconBadgeNumber = 1;
    //设置userinfo
方便在之后需要撤销的时候使用
    NSDictionary
*info = [NSDictionary
dictionaryWithObject:@"name"forKey:@"key"];
   
notification.userInfo = info;
   
//添加推送到UIApplication

UIApplication *app = [UIApplication sharedApplication];
    [app
scheduleLocalNotification:notification]; 
   
}

第二步:接收本地推送
- (void)application:(UIApplication *)application
didReceiveLocalNotification:(UILocalNotification*)notification{

UIAlertView
*alert = [[UIAlertView alloc] initWithTitle:@"iWeibo"
message:notification.alertBody delegate:nil cancelButtonTitle:@"确定"
otherButtonTitles:nil];
    [alert
show];
    //
图标上的数字减1
   
application.applicationIconBadgeNumber -= 1;
}

第三步:解除本地推送
// 获得 UIApplication
UIApplication *app = [UIApplication sharedApplication];
//获取本地推送数组
NSArray *localArray = [app scheduledLocalNotifications];
//声明本地通知对象
UILocalNotification *localNotification;
if (localArray) {
    for
(UILocalNotification *noti in localArray) {
       
NSDictionary *dict = noti.userInfo;
       
if (dict) {
           
NSString *inKey = [dict objectForKey:@"key"];
           
if ([inKey isEqualToString:@"对应的key值"]) {
               
if (localNotification){
                   
[localNotification release];
                   
localNotification = nil;
               
}
               
localNotification = [noti retain];
               
break;
           
}
       
}
    }
   
   
//判断是否找到已经存在的相同key的推送
    if
(!localNotification) {
       
//不存在初始化
       
localNotification = [[UILocalNotification alloc] init];
    }
   
    if
(localNotification) {
       
//不推送 取消推送
       
[app cancelLocalNotification:localNotification];
       
[localNotification release];
       
return;
    }
}

IOS - 本地消息推送的更多相关文章

  1. iOS 本地消息推送机制

    转发自:https://www.jianshu.com/p/e347f999ed95     //已经废除的 http://blog.csdn.net/three_zhang/article/deta ...

  2. iOS 10 消息推送(UserNotifications)秘籍总结(二)

    背景 上一篇博客iOS 10 消息推送(UserNotifications)秘籍总结(一)发布后被 简书编辑推荐至首页,这着实让我受宠若惊啊.可是好事不长,后面发生了让我伤心欲绝的事,我的女朋友不要我 ...

  3. Android本地消息推送

    项目介绍:cocos2dx跨平台游戏 项目需求:实现本地消息推送,需求①:定点推送:需求②:根据游戏内逻辑实现推送(比如玩家体力满时,需要计算后到点推送):需求③:清理后台程序或重启后依然能够实现本地 ...

  4. IOS 本地通知推送消息

    在现在的移动设备中,好多应用性的APP都用到了推送服务,但是有好多推送的内容,比如有的只是单纯的进行推送一个闹钟类型的,起了提醒作 用,有的则是推送的实质性的内容,这就分为推送的内容来区别用什么推送, ...

  5. iOS 之消息推送(个推)---个人小结

    前言:自从上个星期开始整这个推送,弄了差不多一个星期,今天终于给整好了,因此现在来记录这段"奇妙"的旅程. 我们公司使用的消息推送是用的第三方--个推,这里不得不说一下,个推的技术 ...

  6. 分分钟搞定IOS远程消息推送

    一.引言 IOS中消息的推送有两种方式,分别是本地推送和远程推送,本地推送在http://my.oschina.net/u/2340880/blog/405491这篇博客中有详细的介绍,这里主要讨论远 ...

  7. iOS 10 消息推送(UserNotifications)秘籍总结(一)

    前言 之前说会单独整理消息通知的内容,但是因为工(就)作(是)的(很)事(懒)没有更新文章,违背了自己的学习的初衷.因为互联网一定要有危机意识,说不定眼一睁,我们就out丢了饭碗. 图片来源网络.jp ...

  8. xamarin.ios 本地通知推送

    由于ios10版本以后UILocalNotification被标为弃用了,所以要添加新的本地通知推送功能,下面提供一些代码参考. 一.先在AppDelegate.cs上注册本地通知推送功能. publ ...

  9. iOS开发——消息推送跳转

    项目开发用集成是极光推送JPush     这里主要是消息推送过来处理对应界面跳转          同时看到两篇写的不错的相关博客分享一下:      http://www.jianshu.com/ ...

随机推荐

  1. UIView不接受触摸事件的三种情况

    1.不接收用户交互 userInteractionEnabled = NO 2.隐藏 hidden = YES 3.透明 alpha = 0.0 ~ 0.01 4. 如果子视图的位置超出了父视图的有效 ...

  2. 第一个C++例子

    #include <iostream> using namespace std; class Time { private: int hour; int minute; int secon ...

  3. Hdu.1325.Is It A Tree?(并查集)

    Is It A Tree? Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) To ...

  4. compareTo(String str)与compareToIgnoreCase(String str)

    一.compareTo(String str)方法 返回值:如果参数字符串等于此字符串,则返回值 0:如果此字符串按字典顺序小于字符串参数,则返回一个小于 0 的值:如果此字符串按字典顺序大于字符串参 ...

  5. WebStorm设置编辑器中的字体大小

    启动webStorm之后,点击“FIle"菜单,选择其下的”Settings" 2.在左侧的菜单中选择“Editor/Colors & Fonts/Font 在右侧Sche ...

  6. Bootstrap编码规范

    黄金定律 永远遵循同一套编码规范 -- 可以是这里列出的,也可以是你自己总结的.如果你发现本规范中有任何错误,敬请指正.通过 open an issue on GitHub为本规范添加或贡献内容. 不 ...

  7. Java Io 之拷贝文件性能比较

    前面我们共讨论了拷贝文件有三种方式: 1. 第一种,一个字节一个字节的进行拷贝文件操作. 2. 第二种,使用字节数据批量的进行拷贝文件操作. 3. 第三种,使用带缓冲输入输出流来拷贝文件. 那么哪一种 ...

  8. Java 7 Concurrency Cookbook 翻译 第一章 线程管理之五

    九.使用线程本地变量 一个并发程序的最关键特征就是共享数据.这个特性在那些继承了 Thread 类或者 实现了 Runnable 接口的对象上显得更加重要. 如果你创建一个实现了 Runnable 接 ...

  9. spring mvc 传参数

    1.页面:(1)js传参数:location.href="${ctx }/forum/changeCtm.html?ctmId="+id; (2)将内容写在form表单里面,然后用 ...

  10. POJ 1273 网络流(最大流)模板

    http://poj.org/problem?id=1273 这道题很值得反思,弄了一下午,交上去先是一直编译错误,而在本地运行没有问题, 原因可能是oj的编译器版本老旧不支持这样的写法 G[from ...