使用repeatInterval设置的UILocalNotification NSWeekdayCalendarUnit不会每周触发
我正在尝试设置本地通知,每周重复一次。
这是我的设置:
UILocalNotification* localNotification = [[UILocalNotification alloc] init]; ... localNotification.repeatInterval = NSWeekdayCalendarUnit;
在控制台日志中:
localNotif:{开火日期= 2015年4月24日星期五下午12:27:33新加坡标准时间,时区=亚洲/新加坡(GMT + 8)偏移28800,重复间隔= NSWeekdayCalendarUnit,重复计数= UILocalNotificationInfiniteRepeatCount,下一个开火日期= 2015年4月25日星期六下午12:27:33新加坡标准时间,用户信息= {KUserLocalNotficationKey =“2015-04-24 04:27:33 +0000”; }}
如您所见,下一个触发日期将在第二天触发。 这是一个错误吗?
我在iOS 7.1,8.1,8.3中测试过它。
PLz试试这个
UILocalNotification *localNotif=[[UILocalNotification alloc]init]; localNotif.fireDate =currentDate; localNotif.timeZone=[NSTimeZone defaultTimeZone]; localNotif.alertBody = @"MazeRoll"; localNotif.soundName = UILocalNotificationDefaultSoundName; localNotif.applicationIconBadgeNumber = 1; localNotif.repeatInterval=NSWeekCalendarUnit; UIApplication *app=[UIApplication sharedApplication]; [app scheduleLocalNotification:localNotif]; NSLog(@"sdfsdfsdf%@",[[UIApplication sharedApplication] scheduledLocalNotifications]);
你必须像这样编码
UILocalNotification* localNotification = [[UILocalNotification alloc] init]; ... localNotification.repeatInterval = NSCalendarUnitWeekOfYear;
它每周触发通知。
您可以使用NSCalendarUnitWeekOfYear
设置本地通知并设置正确的开火日期。
UILocalNotification *localNotification=[[UILocalNotification alloc]init]; localNotification.fireDate =[NSDate date]; // set your week day on which repeatedly you want local notfication. for example Monday, then set Fire date of next monday. localNotification.timeZone=[NSTimeZone defaultTimeZone]; localNotification.repeatInterval=NSCalendarUnitWeekOfYear; NSLog(@"%@",localNotification);
希望这可以帮助。 享受编码!!
NSDate *currentDate = [NSDate date]; NSDate *futureTime = [currentDate dateByAddingTimeInterval:60*60*168]; NSCalendar *calendar = [NSCalendar currentCalendar]; NSTimeZone *timeZone = [NSTimeZone systemTimeZone]; [calendar setTimeZone:timeZone]; NSDateComponents *components = [calendar components:NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit | NSHourCalendarUnit fromDate:futureTime]; if ([components hour] >= 19) { // make it the next day [components setDay:[components day] + 1 ]; } [components setHour:8]; [components setMinute:00]; NSDate *alertTime = [calendar dateFromComponents:components]; NSLog(@"alertTime %@",alertTime.description); UILocalNotification *localNotif=[[UILocalNotification alloc]init]; localNotif.fireDate =alertTime; localNotif.timeZone=[NSTimeZone defaultTimeZone]; localNotif.alertBody = @"MazeRoll"; localNotif.soundName = UILocalNotificationDefaultSoundName; localNotif.applicationIconBadgeNumber = 1; localNotif.repeatInterval=NSDayCalendarUnit; UIApplication *app=[UIApplication sharedApplication]; [app scheduleLocalNotification:localNotif]; NSLog(@"sdfsdfsdf%@",[[UIApplication sharedApplication] scheduledLocalNotifications]);
- iOS也很有趣,您想尝试一下吗? 来加入我们
- NSFetchedResultsController产生的部分的顺序?
- 如何在执行CIFilter时保留iOS UIImageView中的图像宽高比,如CISepiaTone
- iBeacons:如何获得广播信标功率(txPower)
- 使用Swift Generics识别子类可以使用自定义类,但不能使用UITapGestureRecognizer
- AVAudioEngine inputNode的格式在播放AVAudioPlayerNode时会发生变化
- 主表应用程序
- enumerateBodiesAlongRayStart打印“机会”在Xcode 6控制台
- 更改iOS 7上的标签栏色调颜色