本地推送 到9点自动刷新界面
来源:互联网 发布:手机百度云网络异常 编辑:程序博客网 时间:2024/04/30 10:00
- (void)viewWillAppear:(BOOL)animated
{
[self registUILocalNotification];
}
- (void)viewDidLoad {
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(getNotification) name:@"getNotification" object:nil];
}
- (void)getNotification{
[_tableView.header beginRefreshing];
}
//第一步:创建本地推送
- (void)registUILocalNotification {// 创建一个本地推送
UILocalNotification *notification = [[UILocalNotification alloc] init];
NSDate *currentDate = [NSDate date];//获取当前时间,日期
//把当前时间转化为时间戳
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
NSTimeZone* timeZone = [NSTimeZone timeZoneWithName:@"Asia/Shanghai"];
[dateFormatter setTimeZone:timeZone];
[dateFormatter setDateFormat:@"HH:mm:ss"];
//时间戳
NSTimeInterval nowtime = [currentDate timeIntervalSince1970];
NSTimeInterval period = 0.0;
[dateFormatter setDateFormat:@"YYYY-MM-dd "];
NSString *dateString = [NSString stringWithFormat:@"%@",[dateFormatter stringFromDate:currentDate]];
NSString *AMStr = [NSString stringWithFormat:@"%@%@",dateString,@"09:00:00"];
if (nowtime <= [self turnDayTime:AMStr]){
period = [self turnDayTime:AMStr] - nowtime;
}
if (notification != nil) {//判断系统是否支持本地通知
// 设置推送时间
notification.fireDate = [currentDate dateByAddingTimeInterval:period];
// 设置时区
notification.timeZone = [NSTimeZone defaultTimeZone];
// 设置重复间隔
notification.repeatInterval = kCFCalendarUnitDay;
// 推送声音
notification.soundName = UILocalNotificationDefaultSoundName;
// ios8后,需要添加这个注册,才能得到授权
if ([[UIApplication sharedApplication] respondsToSelector:@selector(registerUserNotificationSettings:)]) {
UIUserNotificationType type = UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | UIUserNotificationTypeSound;
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:type categories:nil];
[[UIApplication sharedApplication] registerUserNotificationSettings:settings];
// 通知重复提示的单位,可以是天、周、月
notification.repeatInterval = NSCalendarUnitDay;
} else {
// 通知重复提示的单位,可以是天、周、月
notification.repeatInterval = NSCalendarUnitDay;
}
//添加推送到UIApplication
[[UIApplication sharedApplication] scheduleLocalNotification:notification];
}
}
在APPDelegate里写代理方法
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification*)notification{
NSLog(@"======9点刷新界面=====");
[[NSNotificationCenter defaultCenter] postNotificationName:@"getNotification" object:nil];
}
0 0
- 本地推送 到9点自动刷新界面
- git推送到服务器自动同步到站点目录
- 界面自动刷新跳转
- Android界面自动刷新
- Fragment界面莫名其妙自动刷新
- Qt界面不自动刷新
- 自动刷新界面方法,兼容问题
- ionic访问界面自动刷新
- 刷新界面 与 到指定界面
- Json数据异步绑定到界面的Table并且自动刷新
- Json数据异步绑定到界面的Table并且自动刷新 .
- git本地建立仓库推送到远程
- GitHub推送本地代码到仓库
- 将本地项目推送到Git
- git将本地项目推送到远程
- 本地代码推送到github的命令
- git 首次推送本地到远程
- git将本地仓库推送到github
- StringBuffer与StringBuilder两者之间的相同处与不同处
- Address Of A Gif
- 修改MenuItem的背景色
- (收藏)嵌入式学习路线
- gulp前端自动化构建工具(三):gulp工具配置文件
- 本地推送 到9点自动刷新界面
- Android Studio设置注解模版
- 解决 side-by-side 问题的一种方法
- git常见命令
- Enum类型详解
- [Leetcode]1. Two Sum
- 在lnmp服务器用file_put_contents函数写入文件无法写入的解决方法
- Android:30分钟弄明白Touch事件分发机制
- Directory Listing For解决方法-tomcat启动,首页报错