Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS 12 Push Notifications are not working and working in below versions , Push notification not receiving in iOS 12

For iOS 12 Push Notifications are not working and working in below versions

My App is in Appstore. Push notification is working fine in iOS 11, but in iOS 12 it is not working. I am not receiving any push notification for iOS 12 devices. I have checked the device token and certificate in my server. All are correct. I have also checked the notification properties in settings app. All are fine. But I didn't receive any notification.

This is the code i used for push notifications.

Can you please suggest me what would be the issue. How to Fix This?

func registerForPushNotifications() {

    if #available(iOS 10.0, *){

        let center = UNUserNotificationCenter.current()
        center.delegate = self
        center.requestAuthorization(options:[.badge, .alert, .sound]) { (granted, error) in
            if (granted)
            {
                UIApplication.shared.registerForRemoteNotifications()
            }
            else{
                //Do stuff if unsuccessful...
                 UIApplication.shared.registerForRemoteNotifications()
            }
            // Enable or disable features based on authorization.
        }
    }
    else
    {

        let types: UIUserNotificationType = [UIUserNotificationType.badge, UIUserNotificationType.alert, UIUserNotificationType.sound]
        let settings: UIUserNotificationSettings = UIUserNotificationSettings( types: types, categories: nil )
        UIApplication.shared.registerUserNotificationSettings( settings )
        UIApplication.shared.registerForRemoteNotifications()

    }

}



@available(iOS 10.0, *)
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {

    let userInfo = response.notification.request.content.userInfo as NSDictionary

    print(userInfo)


}
like image 479
Sandeep Baddula Avatar asked Sep 25 '18 11:09

Sandeep Baddula


Video Answer


1 Answers

I had the same problem when my app running in "debug",
I run app in "release" and notification worked fine

like image 70
Yusef.Naser Avatar answered Oct 08 '22 21:10

Yusef.Naser