本地通知UILocalNotification
];
//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;
}
}
- 第一步:创建本地推送
- // 创建一个本地推送
- UILocalNotification *notification = [[[UILocalNotification alloc] init] autorelease];
- //设置10秒之后
- ];
- if (notification != nil) {
- // 设置推送时间
- notification.fireDate = pushDate;
- // 设置时区
- notification.timeZone = [NSTimeZone defaultTimeZone];
- // 设置重复间隔
- notification.repeatInterval = kCFCalendarUnitDay;
- // 推送声音
- notification.soundName = UILocalNotificationDefaultSoundName;
- // 推送内容
- notification.alertBody = @"推送内容";
- //显示在icon上的红色圈中的数子
- ;
- //设置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
- ;
- }
- 第三步:解除本地推送
- // 获得 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;
- }
- }
本地通知UILocalNotification的更多相关文章
- IOS 本地通知 UILocalNotification
IOS 本地通知 UILocalNotification [本文章第四部分中的代码逻辑来自网上的借鉴,并非我自己原创] 大概一个月前,我开始跟着做IOS项目了.学习C++,了解Objective-C, ...
- 本地通知-UILocalNotification
第一步:创建本地推送 本地通知 UILocalNotification // 创建⼀一个本地推送 UILocalNotification * notification = [[UILocalNotif ...
- ios推送:本地通知UILocalNotification
Notification是智能手机应用编程中非常常用的一种传递信息的机制,而且可以非常好的节省资源,不用消耗资源来不停地检查信息状态(Pooling),在iOS下应用分为两种不同的Notificati ...
- IOS 本地通知UILocalNotification
//发送通知 UILocalNotification *notification=[[UILocalNotification alloc] init]; if (notificati ...
- iOS 注冊本地通知(推送)
注:按Home键让App进入后台执行时.方可查看通知. - (BOOL)application:(UIApplication *)application didFinishLaunchingWithO ...
- iOS 进阶---推送通知之本地通知
1.推送通知的2种方式 1)本地推送通知(Local Notification) 2)远程推送通知(Remote Notification) 2.通知的作用 可以让不在前台运行的app,告知用户app ...
- iOS开发本地通知
/* 本地通知:不通过网络,在本地实现的通知,自己发给自己 远程通知:必须通过网络,使用推送技术(APNs),实现通知 本地通知: 1.要完成可以接收的通知形式的注册 2.具体通知的设置 3.发送通知 ...
- iOS10以前的本地通知和远程通知
一.简介 分为本地推送和远程推送2种.可以在应用没有打开甚至手机锁屏情况下给用户以提示.它们都需要注册,注册后系统会弹出提示框(如下图)提示用户是否同意,如果同意则正常使用:如果用户不同意则下次打开程 ...
- UILocalNotification本地通知的使用方法
本文所写方法主要应用UILocalNotification达到本地推送通知栏信息 取消了其他教程里过期的UIAlertView方法 使用UILocalNotification主要分为创建 调用 取消 ...
随机推荐
- es6中一些基本的使用方法
es6中一些基本的使用方法 const 定义常量 let 块级变量 用let定义的变量只在块当中起作用,离开变量外界的块(括号)就会被销毁. 模板字面量 用于字符串拼接和写模板,使用 ` (反引号,左 ...
- Vue-生命周期图示 注解
根据腾讯课堂视频讲解,将官网生命周期图示进行注解,以加深印象和理解 贴一个源码示例: 注意位置和写法
- angular 按下回车键触发事件
angularJs 按下回车键触发事件这个功能很简单,但是今天的却让我掉坑很久.... 由于我的页面上有两个不同方法都传$event事件,如search($event)和create($event) ...
- 【Demo Project】AjaxSubmit+Servlet表单文件上传和下载
一.背景 前段时间公司要求我做一个上传和下载固件的页面,以备硬件产品在线升级,现在我把这部分功能抽取出来作为一个Demo Project给大家分享. 话不多说,先看项目演示 --> 演示 源码 ...
- form + iframe 获取表单提交后返回的数据
原理: submit 提交表单没有回调函数,但是可以用iframe来接收返回结果,最后进行格式转换就ok了: 原文地址: http://blog.csdn.net/simeng_1016/articl ...
- 方法的重写与重载的区别(Override与Overload)。重载的方法是否可以改变返回值的类型
方法的重写(Override)与重载(Overload)的区别.重载的方法是否可以改变返回值的类型?[基础] 解释: 方法的重写overriding和重载Overloading是Java多态性的不同表 ...
- java反射机制(先马再看)
http://blog.csdn.net/sinat_38259539/article/details/71799078
- Linux档案权限与目录配置
一.档案权限: Linux 最优秀的地方之一,就在于他的多人多任务环境.而为了让各个使用者具有较保密的档案数据,因此档案的权限管理就变的很重要了. Linux 一般将档案可存取的身份分为三个类别,分别 ...
- shell 文本操作命令
vi 编辑器中有三种状态模式 [vi 文件名(或路径+文件名)] 1.命令模式 2.输入模式 3.末行模式 三种模式间的相互转换 vi编辑器的启动与退出 直接进入编辑环境 $ vi 进入编辑环境并打 ...
- MIP (百度移动网页加速器)
前言:第一次用移动网页加速器,感觉好心情都被弄坏了.确实性能提高了不少,但是限制js,对于一些交互实现都成问题.MIP是Mobile Instant Pages的缩写,指百度移动网页加速器, 是一套应 ...