iOS 10 - 每隔"x"分钟重复一次通知

DS.*_*DS. 5 ios swift ios10

在iOS 10中,如何从特定日期/时间开始,在几分钟内设置本地通知重复.

例如,从9月8日上午11点开始,每15分钟触发一次本地通知?假设在下面,dateTimeReminder.date有09/08上午11点.

let dateStart = self.dateTimeNotif.date
let notifTrigger = UNCalendarNotificationTrigger.init(dateMatching: NSCalendar.current.dateComponents([.day, .month, .year, .hour, .minute], from: dateStart), repeats: true)
let notificationRequest = UNNotificationRequest(identifier: "MYNOTIF", content: notifContent, trigger: notifTrigger)

UNUserNotificationCenter.current().add(notificationRequest, withCompletionHandler: nil)
Run Code Online (Sandbox Code Playgroud)

使用上面的代码,我有可能在每个小时的特定时刻,每天的特定时刻安排,等等.但是如何将其变成"每"x"分钟"?任何帮助表示赞赏.

类似的问题 - 如何在iOS 10 UserNotifications上设置NSCalendarUnitMinute repeatInterval?

Ale*_*ano 5

Swift 3/4 和 iOS 10/11

根据此错误,似乎无法使用DateComponents()正确重复本地通知。

您可以使用以下方法代替此方法TimeInterval(如果您的时间间隔大于 60 秒,则此方法有效):

let thisTime:TimeInterval = 60.0 // 1 minute = 60 seconds

// Some examples:
// 5 minutes = 300.0
// 1 hour = 3600.0
// 12 hours = 43200.0
// 1 day = 86400.0
// 1 week = 604800.0

let trigger = UNTimeIntervalNotificationTrigger(
            timeInterval: thisTime,
            repeats: true)
Run Code Online (Sandbox Code Playgroud)


DS.*_*DS. 3

经过大量搜索后,我得出的结论是 Swift 3 目前不支持此功能。对于寻求此功能的每个人,我建议现在使用 UILocalNotification(尽管在 iOS 10 中已弃用),但一旦 UNUserNotification 支持此功能,请稍后迁移到 UNUserNotification。以下是帮助我得出此结论的一些其他问题和资源。另外,请关注该线程中的所有答案和评论,以更深入地了解它所讨论的特定场景。

  • 使用已弃用的 API 通常不是一个好主意。作为一般做法,请尽快迁移到新的 API。不建议将上述解决方案作为永久解决方案。

每两周一次本地通知

http://useyourloaf.com/blog/local-notifications-with-ios-10/

https://github.com/lionheart/openradar-mirror/issues/14941