UILocalNotification
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{ UILocalNotification *notification = [[UILocalNotification alloc] init]; NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"HH:mm:ss"];
// 触发通知的时间
NSDate *now = [formatter dateFromString:@"15:04:00"];
notification.fireDate = now;
// 触发通知的时间
NSDate *currDate = [NSDate date];
NSTimeInterval interval = *; // 半个小时
NSDate *after30minDate = [currDate initWithTimeIntervalSinceNow:+interval];
NSString *currTime = [formatter stringFromDate:after30minDate]; NSDate *notificationTme = [formatter dateFromString:currTime];
notification.fireDate = notificationTme; notification.fireDate = [currDate dateByAddingTimeInterval:];
// 设置时区,默认即可
notification.timeZone=[NSTimeZone defaultTimeZone];
// 通知重复提示的单位,可以是天、周、月
notification.repeatInterval = NSDayCalendarUnit;
// 通知内容
notification.alertBody = @"这是一个新的通知";
// 通知被触发时播放的声音
notification.soundName = UILocalNotificationDefaultSoundName;
// 设置IconBadgeNumber
notification.applicationIconBadgeNumber = [[[UIApplication sharedApplication] scheduledLocalNotifications] count]+;
// 设置本地通知发送的消息,这个消息可以接受
NSDictionary *infoDict = [NSDictionary dictionaryWithObjectsAndKeys:@"setNotificationForEveryDay", @"key", nil];
notification.userInfo = infoDict;
//执行通知注册
[[UIApplication sharedApplication] scheduleLocalNotification:notification];
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
return YES;
} // 应用收到通知时,会调到下面的回调函数
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"LocalNotification" message:notification.alertBody delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil];
[alert show]; //这里可以接受到本地通知中心发送的消息
NSDictionary* dic = notification.userInfo; // 图标上的数字减1
application.applicationIconBadgeNumber -= ; NSLog(@"user info = %@",[dic objectForKey:@"key"]);
}
UILocalNotification的更多相关文章
- iOS调试通过UILocalNotification或RemoteNotification启动的app
相信很多同学都为调试苹果的通知烦恼过,特别是通过通知启动app这个功能,简直让人欲哭无泪!!! 然而我们都遇到的问题,苹果怎么可能没有想到,原来早就有了官方的解决办法,只是我们不知道而已... 这次又 ...
- 用UILocalNotification实现一个闹钟(Swift)
之前项目需求要实现一个闹钟,github上找了半天发现都是很旧的代码了,所以就准备自己写一个,刚好最近在学习Swift,就用Swift写了一个demo放在这里:https://github.com/P ...
- UILocalNotification本地通知的使用方法
本文所写方法主要应用UILocalNotification达到本地推送通知栏信息 取消了其他教程里过期的UIAlertView方法 使用UILocalNotification主要分为创建 调用 取消 ...
- 本地推送UILocalNotification
//本地推送---无需网络,由本地发起 UILocalNotification *localNotification = [[UILocalNotification alloc]init]; //设置 ...
- ios 把已经点击过的UILocalNotification 从系统的通知中心现实中移除
在ios7 上一个uilocalnotification在中心现实后,点击该消息,程序被唤醒了,但是该通知没有被移除.用了以下的代码后可以解决这个问题 UIApplication.sh ...
- iOS UILocalNotification 每2周,每两个月提醒
iOS 的UILocalNotification提醒提供了默认的重复频率,比如,一天,一个星期等等,但是对于非标准的频率,比如每,2周,每2个月,无法重复提醒. 我们的思路是在应用程序开始时,把即将发 ...
- iOS - iPhone开发 UILocalNotification的使用
OS下的Notification的使用 Notification 是智能手机应用编程中非常常用的一种传递信息的机制,而且可以非常好的节省资源,不用消耗资源来不停地检查信息状态(Pooling),在iO ...
- Swift - 推送之本地推送(UILocalNotification)添加Button的点击事件
上一篇讲到的本地推送是普通的消息推送,本篇要讲一下带按钮动作的推送消息 import UIKit @UIApplicationMain class AppDelegate: UIResponder, ...
- Swift - 推送之本地推送(UILocalNotification)
// 本地推送通知是通过实例化UILocalNotification实现的.要实现本地化推送可以在AppDelegate.swift中添加代码实现,本事例是一个当App进入后台时推送一条消息给用户. ...
- ios推送:本地通知UILocalNotification
Notification是智能手机应用编程中非常常用的一种传递信息的机制,而且可以非常好的节省资源,不用消耗资源来不停地检查信息状态(Pooling),在iOS下应用分为两种不同的Notificati ...
随机推荐
- PHP文件目录copy
/**(2) PHP文件目录copy @param string $dirsrc 原目录名称字符串 @param string $dirto 目标目录名称字符串 */ function copyDir ...
- [最新版]MJRefresh解析与详细使用指导
俗话说 "工欲善其事,必先利其器",好的成熟的第三方,是我们开发路上的利器:俗话又说"君子生非异也,善假于物也"NB的人并不是生下来就和别人不一样,只是他们擅于 ...
- vs2010 正式版官方下载地址
北京时间2010年4月12日12:00,微软Visual Studio 2010 正式版提供官方下载,眼下有三个版本号,Professional/Premium/Ultimate. 注意原页面的链接R ...
- 把一个select查询结果插入到一个表(可选指定字段和值实例)
把一个select查询结果插入到一个表(可选指定字段和值实例) insert into bak (cc,yf) select cc,9 from ket insert into bak (cc,yf ...
- django中的Model模型一:
在django的框架设计中采用了mtv模型,即Model,template,viewer Model相对于传统的三层或者mvc框架来说就相当对数据处理层,它主要负责与数据的交互,在使用django框架 ...
- Common Table Expressions (CTE)
子查询有时使用起来很麻烦,因为所有的过滤和匹配逻辑都必须集成到子查询表达式中.如果只需要执行一个任务,且只需要使用一次杳询表达式,子查询是很好的选择.但子查询不能被重用,也不能很好地支持多个需求.这个 ...
- flex 调用WebService2(基于.net)
flex 访问WebService的方法有很多种,使用FLEX4中的"数据/服务"功能可以自动生成访问WebService的代理类,这样可以避免把所有的数据访问都写到MXML页面上 ...
- iOS 之 cocoapods安装与使用
我们都知道第三方库,一般使用cocoapods管理,cocoapods在我们IOS开发中有着很大的作用. 好了,现在看下它的安装步骤: 1.打开终端,输入 sudo gem install cocoa ...
- .Net Memory -- Windbg基本命令
命令 解释 .cls 清空命令窗口屏幕 .load dllfullpath 加载debugger扩展dll如SOS sosex psscor. .loadby dll moduleName 加载deb ...
- WCF入门教程系列一
一.概述 Windows Communication Foundation(WCF)是由微软发展的一组数据通信的应用程序开发接口,可以翻译为Windows通讯接口,它是.NET框架的一部分.由 .NE ...