Register and Schedule Local Notification in Swift 3.0 iOS 10

suggest change

Registration

in AppDelegate

import UserNotifications

in didFinishLaunchingWithOptions method,

UNUserNotificationCenter.current().requestAuthorization(options: [.alert,.sound,.badge]) { (granted, error) in

// Here you can check Request is Granted or not.

}

Create and Schedule notification.

let content = UNMutableNotificationContent()
content.title = "10 Second Notification Demo"
content.subtitle = "From Wolverine"
content.body = "Notification after 10 seconds - Your pizza is Ready!!"
content.categoryIdentifier = "myNotificationCategory"

let trigger = UNTimeIntervalNotificationTrigger(
    timeInterval: 10.0,
    repeats: false)

let request = UNNotificationRequest(
    identifier: "10.second.message",
    content: content,
    trigger: trigger
)
UNUserNotificationCenter.current().add(request, withCompletionHandler: nil)

Where ever this part of code is triggered, If you have allowed Notification Permission, you will receive an notification.

To test it properly, Make sure your application in Background mode.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:


UILocalNotification:
* Register and Schedule Local Notification in Swift 3.0 iOS 10

Table Of Contents
6 UILocalNotification
12 UIView
15 UIColor
26 UIImage
28 CALayer
30 NSDate
40 iBeacon
49 NSTimer
79 NSURL
87 AWS SDK
96 NSData
101 Segues
104 EventKit
105 NSBundle
106 SiriKit
111 StoreKit
117 3D Touch
119 Keychain
122 Block
141 AirDrop
144 UISlider
145 Carthage
146 HealthKit
151 plist
157 MVVM
164 UIPhoenix
166 Simulator
168 NSArray
169 OpenGL
175 Core Data
179 MyLayout
180 UIFont
189 Security
200 Codable