UILocalNotification的使用
来源:互联网 发布:千里眼定位软件 编辑:程序博客网 时间:2024/05/21 19:26
UILocalNotification一般做为定时器使用,可以定时提醒,定时唤醒。
1.对象的创建
UILocalNotification *notification = [[UILocalNotification alloc] init];
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
NSString *noticeDate = @"2012-07-30 12:00:00";
formatter.dateFormat = @"yyyy-MM-dd HH:mm";
//设置触发时间
notification.fireDate = [formatter dateFromString:noticeDate];
[formatter release];
//触发频率,0表示只有一次,频率不能为自定义的
notification.repeatInterval = 0;
notification.repeatInterval = kCFCalendarUnitDay;
notification.repeatInterval = kCFCalendarUnitWeek;
//用户信息,为字典类型,内容可以自己设定,这里存放了唯一的key做为标记
NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:
[NSString stringWithFormat:@"%d", noticeInfo.notifyID],KEY,nil];
[notification setUserInfo:dict];
//提醒内容
notification.alertBody = @“HELLO”;
//提醒铃音必须为默认的或声音文件
notification.soundName = UILocalNotificationDefaultSoundName;//@"ping.caf";//
2.对象的管理
//获取当前所有提醒,内容为UILocalNotification数组
[[UIApplication sharedApplication] scheduledLocalNotifications];
//添加提醒
UIApplication *app = [UIApplication sharedApplication];
[app scheduleLocalNotification:notification];
//取消提醒,遍历所有提醒,从中找到需要取消的那个
NSArray *myArray=[[UIApplication sharedApplication] scheduledLocalNotifications];
for (UILocalNotification *myUILocalNotification in myArray) {
if ([[[myUILocalNotification userInfo] objectForKey:KEY] intValue] == value) {
[[UIApplication sharedApplication] cancelLocalNotification:myUILocalNotification];
return;
}
}
//取消所有提醒
UIApplication *app = [UIApplication sharedApplication];
[app cancelAllLocalNotifications];
3.提醒的处理,提醒触发时会回调appdelegate的如下方法
- (void)application:(UIApplication *)app didReceiveLocalNotification:(UILocalNotification *)notif
{
MessageBox *messageBox = [MessageBox sharedInstance];
[messageBox showMessageBoxWithTitle:@"本地提醒"
message:notif.alertBody
delegate:self
cancelButtonTitle:@"OK"
msgBoxType:E_TYPE_OK];
}
- UILocalNotification的使用
- UILocalNotification 的使用
- UILocalNotification的使用
- UILocalNotification的使用
- UILocalNotification的使用
- UILocalNotification的使用
- UILocalNotification的使用
- UILocalNotification的使用
- UILocalNotification的使用
- UILocalNotification的使用
- UILocalNotification的使用
- iPhone开发 UILocalNotification的使用
- iPhone开发 UILocalNotification的使用
- iOS下UILocalNotification的使用
- iPhone开发 UILocalNotification的使用
- iPhone开发 UILocalNotification的使用
- 本地通知 UILocalNotification的使用
- iOS下的UILocalNotification的使用
- UNION ALL多表搜索查询
- kohana的路由roule设置modules/init.php
- db写法query
- kohana从模型model继承Model_Database获取数据库数据
- kohana控制器目录与类class写法关系class Controller_a_b_c_d_admin
- UILocalNotification的使用
- kohana视图view加载顺序 先加载模板 再定义变量
- kohana路由roule与模块modules的关系init.php(默认加载模块hmvc)
- kohana自定义site_url去除index.php
- kohana模块mocules是如何工作的(级联文件系统)
- kohana验证规则rules
- JavaScript 比较和逻辑运算符
- kohana框架类扩展透明性
- oracle数据库导出ORA-39127错误解决方案