【发布时间】:2016-06-23 06:01:18
【问题描述】:
直到iOS 9 我们这样写local notifications
UILocalNotification* localNotification = [[UILocalNotification alloc] init];
localNotification.fireDate = pickerDate;
localNotification.alertBody = self.textField.text;
localNotification.timeZone = [NSTimeZone defaultTimeZone];
localNotification.repeatInterval = NSCalendarUnitMinute;
localNotification.applicationIconBadgeNumber = [[UIApplication sharedApplication] applicationIconBadgeNumber] + 1;
[[UIApplication sharedApplication] scheduleLocalNotification:localNotification];
在本地通知中我们有repeatInterval,现在在WWDC2016 Apple 宣布User Notification 包含
- UNTimeIntervalNotificationTrigger。
-
UNCalendarNotificationTrigger.
UNTimeIntervalNotificationTrigger* trigger = [UNTimeIntervalNotificationTrigger triggerWithTimeInterval:60 repeats:YES];
上面的代码将在每分钟后触发通知。但无法设置日期。
NSDateComponents* date = [[NSDateComponents alloc] init];
date.hour = 8;
date.minute = 30;
UNCalendarNotificationTrigger* triggerC = [UNCalendarNotificationTrigger triggerWithDateMatchingComponents:date repeats:YES];
上面的代码可以设置日期和重复将在明天 8:30 触发,而不是在分钟之后。
在 iOS 10 User Notification 中,我如何像在 UILocalNotification 中设置一样设置重复频率的日期时间?
我想在明天晚上 8:30 安排User Notification,并在每分钟之后重复一次,就像我在顶部指定的关于local notification 的代码一样
【问题讨论】:
-
大家好,我也有同样的问题。请让我们知道是否有人已经实现了此功能? 仅供参考: 问题是“如何为 iOS 10 中的本地通知设置重复间隔,例如每天、每月、每分钟等”。我在等。谢谢。
-
找到解决上述问题的方法了吗?
标签: ios objective-c nsdate uilocalnotification nsdatecomponents