简体   繁体   中英

iOS 10 User Notifications does not allow repeating of notifications at intervals

http://www.openradar.me/26855019

With the new iOS 10 User Notifications framework, one can no longer schedule notifications at a specific date or time that repeats every minute or every hour.

How can I do it in User Notifications framework?

I found this:

https://developer.apple.com/library/content/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/SchedulingandHandlingLocalNotifications.html#//apple_ref/doc/uid/TP40008194-CH5-SW1

You can try to define categories for UNNotificationResponse, then handle response depends on category type.

func userNotificationCenter(_ center: UNUserNotificationCenter,
                            didReceive response: UNNotificationResponse,
                            withCompletionHandler completionHandler: @escaping () -> Void) {
    if response.notification.request.content.categoryIdentifier == "TIMER_EXPIRED" {
        // Handle the actions for the expired timer.
        if response.actionIdentifier == "SNOOZE_ACTION" {
            // Invalidate the old timer and create a new one. . .
        }
        else if response.actionIdentifier == "STOP_ACTION" {
            // Invalidate the timer. . .
        }
    }

    // Else handle actions for other notification types. . .
}

You can trigger a notification based on time, calendar or location. The trigger can be repeating:

let date = Date(timeIntervalSinceNow: 60)
let triggerMinute = Calendar.current.dateComponents([.minute,.second], from: date)
let trigger = UNCalendarNotificationTrigger(dateMatching: triggerMinute, repeats: true)

This code attempts to schedule notification such that the minute & second components of the date matches, you could configure it in the way you want.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM