iOS开发之系统后台运行弹出本地通知
2013-12-20 10:38
417 查看
后台指定时间弹出通知信息:
执行以下代码就可以在每天的指定时间弹出消息,就算是程序被结束之后,同样可以弹出。
UILocalNotification*UILocalNotification alloc] init];
if (nil != notification)
{
//
设置弹出通知的时间
NSDateFormatter *[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"HH:mm"];
NSDate *nowDate = [dateFormatter dateFromString:@"09:54"];
//设置通知弹出的时间
notification.fireDate = nowDate;
//设置重复重复间隔为每天
notification.repeatInterval = kCFCalendarUnitDay;
//
设置时区
notification.timeZone= [NSTimeZone defaultTimeZone];
//设置提示消息
notification.alertBody = [NSString stringWithFormat:@"%@",@"通知来了"];
//
设置启动通知的声音
notification.soundName = UILocalNotificationDefaultSoundName;
//
启动通知
[[UIApplication sharedApplication]scheduleLocalNotification:notification];
}
执行以下代码就可以在每天的指定时间弹出消息,就算是程序被结束之后,同样可以弹出。
UILocalNotification*UILocalNotification alloc] init];
if (nil != notification)
{
//
设置弹出通知的时间
NSDateFormatter *[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"HH:mm"];
NSDate *nowDate = [dateFormatter dateFromString:@"09:54"];
//设置通知弹出的时间
notification.fireDate = nowDate;
//设置重复重复间隔为每天
notification.repeatInterval = kCFCalendarUnitDay;
//
设置时区
notification.timeZone= [NSTimeZone defaultTimeZone];
//设置提示消息
notification.alertBody = [NSString stringWithFormat:@"%@",@"通知来了"];
//
设置启动通知的声音
notification.soundName = UILocalNotificationDefaultSoundName;
//
启动通知
[[UIApplication sharedApplication]scheduleLocalNotification:notification];
}
相关文章推荐
- IOS程序内发短信 MFMessageComposeViewController
- ios开发获得ip
- IOS基础学习日志(五)简单的表格及表视图
- Xcode做ios开发时 message sent to deallocated instance问题的解决方法(gdb和lldb)
- 定制iOS 7中的导航栏和状态栏
- ios程序内实现打电话
- iOS技巧之Notification,BadgeView
- iOS7开发~Xcode5制作framework
- cocoa2d (游戏开发)
- iOS代码技巧之判断设备及状态
- iOS-图片可以自适应屏幕大小吗,应该会失真吧?
- iOS-屏幕横屏,键盘也横屏,怎么设置呢?
- 【转】iOS:hidesBottomBarWhenPushed的正确用法
- 关闭iOS虚拟键盘的N种方法
- iOS学习资料分享 -- 苹果官方iPhone应用高级开发课程(16集)
- iOS 应用内付费(IAP)开发步骤
- 第一章 BIOS
- iOS7 中的新特性
- ios notification
- iOS应用性能调优的25个建议和技巧