Instance Method

add(_:withCompletionHandler:)

Schedules a local notification for delivery.

Declaration

func add(_ request: UNNotificationRequest, withCompletionHandler completionHandler: ((Error?) -> Void)? = nil)

Parameters

request

The request object containing the notification payload and trigger information. This parameter must not be nil.

completionHandler

The block to execute with the results. This block may be executed on a background thread. The block has no return value and takes the following parameter:

error

An error object indicating whether a problem occurred. If the notification was scheduled successfully, this parameter is nil; otherwise, it is set to an error object indicating the reason for the failure.

Discussion

This method schedules local notifications only; you cannot use it to schedule the delivery of remote notifications. Upon calling this method, the system begins tracking the trigger conditions associated with your request. When the trigger condition is met, the system delivers your notification. If the request does not contain a UNNotificationTrigger object, the notification is delivered right away.

You may call this method from any thread of your app.

See Also

Scheduling and Canceling Notification Requests

func getPendingNotificationRequests(completionHandler: ([UNNotificationRequest]) -> Void)

Returns a list of all notification requests that are scheduled and waiting to be delivered.

func removePendingNotificationRequests(withIdentifiers: [String])

Unschedules the specified notification requests.

func removeAllPendingNotificationRequests()

Unschedules all pending notification requests.