iOS开发本地通知(每天定点发送消息推送)
来源:互联网 发布:java汽车租赁项目 编辑:程序博客网 时间:2024/05/29 10:42
NSDate now = [NSDate date];
//取得系统时间
NSCalendar calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian];
NSDateComponents *components = [[NSDateComponents alloc] init];
NSInteger unitFlags = NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay | NSCalendarUnitWeekday | NSCalendarUnitHour | NSCalendarUnitMinute | NSCalendarUnitSecond;
components = [calendar components:unitFlags fromDate:now];
NSInteger hour = [components hour];
NSInteger min = [components minute];
NSInteger sec = [components second];
NSInteger week = [components weekday];
NSLog(@"现在是%ld:%ld:%ld,周%ld",hour,min,sec,week);
UILocalNotification *localNotification = [[UILocalNotification alloc] init];//设置时区(跟随手机的时区)localNotification.timeZone = [NSTimeZone defaultTimeZone];if (localNotification) { localNotification.alertBody = @"消息推送消息推送"; localNotification.alertAction = @"打开"; //小图标数字 localNotification.applicationIconBadgeNumber = 0; NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; [formatter setDateFormat:@"HH:mm:ss"]; NSDate *date = [formatter dateFromString:@"15:30:00"]; //通知发出的时间 localNotification.fireDate = date;}//循环通知的周期localNotification.repeatInterval = kCFCalendarUnitDay;//设置userinfo方便撤销NSDictionary *info = [NSDictionary dictionaryWithObject:@"name" forKey:@"key"];localNotification.userInfo = info;//启动任务[[UIApplication sharedApplication] scheduleLocalNotification:localNotification]; *//*for (UILocalNotification *obj in [UIApplication sharedApplication].scheduledLocalNotifications) { if ([obj.userInfo.allKeys containsObject:kLocalNotificationKey]) { [[UIApplication sharedApplication] cancelLocalNotification:obj]; }}// 设置一个按照固定时间的本地推送NSDate *now = [NSDate date];//取得系统时间NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian];NSDateComponents *components = [[NSDateComponents alloc] init];NSInteger unitFlags = NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay | NSCalendarUnitWeekday | NSCalendarUnitHour | NSCalendarUnitMinute | NSCalendarUnitSecond;components = [calendar components:unitFlags fromDate:now];NSInteger hour = [components hour];NSInteger min = [components minute];NSInteger sec = [components second];NSInteger week = [components weekday];WDLog(@"现在是%ld:%ld:%ld,周%ld",hour,min,sec,week);UILocalNotification *localNotification = [[UILocalNotification alloc] init];//设置时区(跟随手机的时区)localNotification.timeZone = [NSTimeZone defaultTimeZone];if (localNotification) { localNotification.alertBody = @"消息推送消息推送"; localNotification.alertAction = @"打开"; //小图标数字 localNotification.applicationIconBadgeNumber = 0; NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; [formatter setDateFormat:@"HH:mm:ss"]; NSDate *date = [formatter dateFromString:@"15:30:00"]; //通知发出的时间 localNotification.fireDate = date;}//循环通知的周期localNotification.repeatInterval = kCFCalendarUnitDay;//设置userinfo方便撤销NSDictionary *info = [NSDictionary dictionaryWithObject:@"name" forKey:@"key"];localNotification.userInfo = info;//启动任务[[UIApplication sharedApplication] scheduleLocalNotification:localNotification]; *//*for (UILocalNotification *obj in [UIApplication sharedApplication].scheduledLocalNotifications) { if ([obj.userInfo.allKeys containsObject:kLocalNotificationKey]) { [[UIApplication sharedApplication] cancelLocalNotification:obj]; }}//直接取消全部本地通知//[[UIApplication sharedApplication] cancelAllLocalNotifications];
0 0
- iOS开发本地通知(每天定点发送消息推送)
- iOS开发推送本地通知
- iOS开发:本地通知(推送)
- 本地通知和推送通知 - iOS开发
- ios 本地通知与消息推送
- iOS本地通知——每天固定时间发送通知
- iOS本地通知——每天固定时间发送通知
- iOS本地通知——每天固定时间发送通知
- iOS 设置每天下午4点推送本地通知
- iOS 设置每天下午4点推送本地通知
- iOS本地推送(本地通知)
- iOS本地推送(本地通知)
- iOS 本地推送 (本地通知)
- iOS本地推送(本地通知)
- iOS本地推送(本地通知)
- iOS本地推送(本地通知)
- iOS本地推送(本地通知)
- iOS本地推送(本地通知)
- 动态规划:青蛙跳台阶、变态跳台阶
- JavaSE入门学习51:多线程编程(二)
- 206. Reverse Linked List
- ISBN号码
- 经典面试题——赋值运算符的重载
- iOS开发本地通知(每天定点发送消息推送)
- QTable Widget
- Android OnClickListener 使用总结
- spark在windows本地调试
- JDK1.8版本下载及环境变量配置
- Qt + ffmpeg播放器
- 简单crm的项目实现(第一天)
- Windows中BeautifulSoup的安装方法
- bootstrap-table 实现单击单元格可编辑