这个问题在这里已有答案:
直到 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
中如何设置重复频率的日期时间,就像我们可以在_900113中设置一样?
我想明天晚上8:30安排 User Notification
并在每分钟后继续重复,就像我在顶部指定的代码 local notification
2 回答
对于iOS 10,您可以这样使用:
它与iOS 9代码具有相同的效果 . 要重复,您只需使用要重复的组件即可 .
受@Ramon Vasconcelos的启发,我使用以下代码一起设置间隔和fireDate