Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trouble receiving push notifications in iOS10 and iOS9

Tags:

Trying to set up push notification for iOS10. had it working previously for versions below 10.
Read through some guides my setup is like so:

// Register for the defined notifications

        if #available(iOS 10.0, *) {

            let center = UNUserNotificationCenter.current()
            center.delegate = UIApplication.shared.delegate as! AppDelegate
            center.requestAuthorization(options: [.alert, .badge, .sound]) { (granted, error) in

                if error == nil {
                    UIApplication.shared.registerForRemoteNotifications()
                }
            }

        } else {

            // Fallback on earlier versions

            let notificationSettings = UIUserNotificationSettings(types: [.alert, .badge, .sound], categories: [autoCancelCategory])
            UIApplication.shared.registerUserNotificationSettings(notificationSettings)
            UIApplication.shared.registerForRemoteNotifications()

        }

This is called on login ^ in one of my view controllers.

And now in AppDelegate, it conforms to UNUserNotificationCenterDelegate, I have these methods:

@available(iOS 10.0, *)
func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
    print("Got a push!")
}


@available(iOS 10.0, *)
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
    print("Got a push!")
}

And I also have:

 func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {

    let settings = UserDefaults.standard
    settings.setValue(deviceToken, forKey: "deviceToken")
}

The device token is uploaded to the server as Data, and this has worked fine for previous versions.
I have checked that the token on the server matches the one on the phone.
I have enabled push notifications for all targets in Capabilities, I have also ticked Add the push Notifications entitlement to your entitlements file.
Not receiving anything at all though on the push.
Any ideas what I might be doing wrong here? Any pointers would be really appreciated!

Thanks!

EDIT: I have also noticed that the push notifications are not working in iOS9.

like image 251
Kex Avatar asked Sep 30 '16 10:09

Kex


People also ask

Why push notification is not working for iOS?

You can fix an iPhone that's not getting notifications by restarting it or making sure notifications are turned on. You should also make sure your iPhone is connected to the internet so apps can receive notifications. If all else fails, you should try resetting the iPhone — just make sure to back it up first.

Why are push notifications not working?

One of the main reasons why your phone's notifications aren't working could be due to broken app updates. If your Android device is not getting notifications from one app in particular, it's possible that the developers have accidentally rolled out a buggy update.

Why dont I get notifications iOS 15?

To turn it off, go to Settings > Do not Disturb to toggle it off. If your iPhone is running iOS 15, you need to open Settings > Focus > Do Not Disturb. When you disable the Do Not Disturb mode, the iPhone push notifications not working issue should be fixed.


1 Answers

Have you checked that Build Settings > Code Signing Entitlements has a reference to entitlements file? [AppName].entitlements.

And that the entitlements file contains the correct info:

(key: APS Environment, value: development)

Other than that, you can try regenerating push certificates. We had to create new certificates to get it to work in production after IOS 10 upgrade (but not in sandbox environment).

like image 163
Rasmus Höglund Avatar answered Oct 01 '22 01:10

Rasmus Höglund