如何在iOS 10 UserNotifications上设置NSCalendarUnitMinute repeatInterval?

S.J*_*S.J 9 objective-c ios swift ios10 unnotificationrequest

在UILocalNotification我们使用NSCalendarUnitMinute像重复.....但我在iOS 10 UserNotification doc中找不到...我怎样才能NSCalendarUnitMinute在iOS 10中使用类似的重复UserNotification

这是代码,它将在晚上8:30安排本地通知,并在每一分钟后重复.

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];
Run Code Online (Sandbox Code Playgroud)

JAL*_*JAL 1

使用UNCalendarNotificationTriggerwithDateComponents代替NSCalendar

var date = DateComponents()
date.hour = 8
date.minute = 30

let trigger = UNCalendarNotificationTrigger(dateMatching: date, repeats: true)
let content = UNNotificationContent()
// edit your content

let notification = UNNotificationRequest(identifier: "myNotification", content: content, trigger: trigger)
Run Code Online (Sandbox Code Playgroud)

您可以使用实例设置日期DateComponents,并指定通知是否应使用初始值设定repeats项的参数重复UNCalendarNotificationTrigger

UNCalendarNotificationTrigger 文档

请注意,Apple 文档中存在拼写错误(截至 6/13)。如果您使用NSDateComponents而不是DateComponents,则需要date as DateComponentsdateMatching参数中显式转换您。

针对您的评论,我不认为 . 支持您想要的行为(更改重复通知的频率)UNCalendarNotificationTrigger