9
votes

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)


}
1
@Anbu.karthik push notifications are working below iOS 12 versions both background and foreground, the issue is only with iOS 12.Sandeep Baddula
give the time, I will check and update youAnbu.Karthik
did you find a solution to your issue?Abdullah Umer
@SandeepBaddula Have you found any solution ?US-1234

1 Answers

3
votes

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