本地通知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主要分为创建 调用 取消 ...
随机推荐
- 【BZOJ4010】【HNOI2015】菜肴制作(拓扑排序)
[BZOJ4010][HNOI2015]菜肴制作(拓扑排序) 题面 Description 知名美食家小 A被邀请至ATM 大酒店,为其品评菜肴. ATM 酒店为小 A 准备了 N 道菜肴,酒店按照为 ...
- 误操作导致 lvdisplay 命令不存在解决
1.lvdisplay 命令不存在 查看lvm2 包被卸载2.执行 yum install lvm2 命令 发现 yum 被锁 3.删除yum.lock 发现/ 目录只读4.mount -o remo ...
- eclipse 中启动Tomcat超时了错误
修改E:\eclipse\eclipse\workspace\.metadata\.plugins\org.eclipse.wst.server.core\servers.xml 将 start-ti ...
- 找出k个数相加得n的所有组合
Find all possible combinations of k positive numbers that add up to a number n,each combination shou ...
- 今天给大家分享用Python matplotlib来写随机漫步的小程序
先安装两个库: pip install matplotlib pip install numpy 引用库: import matplotlib.pyplot as mp import numpy as ...
- IM-iOS退出后台接受消息,app退出后台能接收到推送
App被失活状态的时候可以走苹果的APNS:但是在活跃的时候却接受不到推送! 那就用到本地推送:UILocalNotification 消息神器. 处理不好可能会有很多本地推送到来,那么问题来了要在什 ...
- emacs在windows下打开报错原因
最开始实在是想不通,最开始我明明就能正常使用,后来发现不能用了,过了几天才回过神来,我路径中有中文,换了一个没有中文的路径后打开正常了.太低级的错误了嘛,却那么难发现. 这些数字就是识别不出来我的中文 ...
- 设计模式——建造者模式/生成器模式(C++实现)
#include <iostream> #include <string> using namespace std; class STProduct { public: voi ...
- python虚拟环境介绍与安装
视频链接: http://edu.tv.sohu.com/play/sid/8fefb999e05c5b01 1.为什么安装虚拟环境? 因为python框架更新迭代太快,有时电脑上存在一个框架多个版 ...
- maven依赖大全
1.oracle mysql驱动 <!-- mysql驱动支持 --> <dependency> <groupId>mysql</groupId> &l ...