First of all, you should consider the fact that the UILocalNotification class that you are using has been deprecated since iOS 10. Since iOS 10 there is no difference between local and remote notifications.
In the UserNotifications framework (iOS 10.0+, Swift | Objective-C), UNNotification instances are not created, as in some previous implementations of similar Apple frameworks / APIs. Instead, the UNNotificationCenter instance UNNotificationCenter responsible for creating notification objects and invokes delegation methods when new notifications are received and before the default user interface is displayed. For more information on UNUserNotificationCenterDelegate protocol UNUserNotificationCenterDelegate see Apple documentation . I often end up using AppDelegate as a class conforming to this protocol
Now back to the question. To initiate the creation of a notification from the application first, you must create a trigger (in your case, you can use the UNTimeIntervalNotificationTrigger ), then create a notification request and, finally, add the request to the plain notification center, which can be accessed by calling UNUserNotificationCenter.current() .
let content = UNMutableNotificationContent() content.title = "Alert Fired"
Create a trigger that determines when UNUserNotificationCenter triggers a notification
let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 0, repeats: false)
Create a notification request. You only create those that trigger local notifications, since iOS is responsible for creating request objects for incoming push notifications.
let request = UNNotificationRequest(identifier: "FiveSecond", content: content, trigger: trigger)
Now we will need to add our request to the current notification center associated with our application.
let center = UNUserNotificationCenter.current() center.add(request, withCompletionHandler: nil)
In our case, the notification will be immediately initiated by the UNUserNotificationCenter.