Ios 11- User local notification wich repeat every x minutes

安稳与你 提交于 2020-01-06 05:05:13

问题


In iOS 11, How can I implement a local notification which repeats every x minutes? The repeating interval will be selected from the user. So for example let's say that a user choose to set a notification which will trigger tomorrow at 9:00 AM and from there it triggers every 2 days (or two weeks or 6 months or 10 minutes)

var repeatInterval = Bool()

trigger = UNCalendarNotificationTrigger(dateMatching: triggerDate, repeats: repeatInterval)

//Schedule the Notification
let identifier = titleNospace
let request = UNNotificationRequest(identifier: identifier!, content: content, trigger: trigger)
self.center.add(request, withCompletionHandler: { (error) in
    if let error = error {
        print(error.localizedDescription)
    }
})
UNUserNotificationCenter.current().add(notificationRequest, withCompletionHandler: nil)

With this code I can schedule a notification at a set date. I've been told that from here if I would like to schedule a repeat notification I should use a triggerInterval when the notification is delivered. But how can I do so? How can I get the value of the repeating time (defined by the user) when the notification is delivered? Shall I use this?:

func didReceive(_ notification: UNNotification)

I've tried but it seems that it's never called.

I'm new to swift and I've tried and tried but it seems I cannot find a solution. I've been able to manage the repeating hourly, monthly, daily and yearly. If I would like to add a custom repeat though I really wouldn't know how to do.

Any help is really appreciated!

Thank you


回答1:


For your information you can't do customise repeat time interval like every 2 min, 10 min or Etc. you must use value of NSCalendarUnit like

How to set repeat frequency in User Notification



来源:https://stackoverflow.com/questions/46094716/ios-11-user-local-notification-wich-repeat-every-x-minutes

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!