Please try this:
extension AppDelegate: UNUserNotificationCenterDelegate {
func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
completionHandler([.alert, .sound])
}
}
You can find Apple doc here.
What I have understood is, whatever options I send to completionHandler
will happen.
If you send just .alert
, it will just show the alert
If you send just .sound
, it will just play the sound specified by notification.
And will do both if we send both options.
And will do nothing if we don't send any parameter.
So what you need to do is send parameter as .alert
.
In didFinishLaunchingWithOptions
you will also need to add
UNUserNotificationCenter.current().delegate = self