Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ios 9 push notification not showing while app is open

Tags:

ios

swift2

if (deviceToken == nil) {
            print("There is no deviceToken saved yet.")
            let settings = UIUserNotificationSettings(forTypes: [.Alert, .Badge, .Sound], categories: nil)
            UIApplication.sharedApplication().registerUserNotificationSettings(settings)
            UIApplication.sharedApplication().registerForRemoteNotifications()
        }

This my code for permission.

like image 390
Janak LN Avatar asked Jan 19 '26 15:01

Janak LN


1 Answers

Need to add the completionHandler part, otherwise push notification is received. but it will be not shown.

@available(iOS 10.0, *)
    func userNotificationCenter(_ center: UNUserNotificationCenter,  willPresent notification: UNNotification, withCompletionHandler   completionHandler: @escaping (_ options:   UNNotificationPresentationOptions) -> Void) {
  completionHandler([.alert, .badge, .sound])
}
like image 102
Oshitha Wimalasuriya Avatar answered Jan 21 '26 07:01

Oshitha Wimalasuriya



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!