iOS application missing from notification center [

2019-03-18 06:52发布

问题:

Problem: The app doesn't appear on notification center and it is unable to receive push notifications right after installation completes and the app registers for push notifications via registerForRemoteNotificationTypes:.

Details:

  • The app usually appears in notification center after the device is restarted and after that everything works just fine.
  • Sometimes the app shows up in notification center right after intallation and registration for APNs(I still can't confirm this but I think I stumbled upon such situations).
  • The app calls the method registerForRemoteNotificationTypes each time a user logins and each time a user logouts respectively with bit masks (UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound) and UIRemoteNotificationTypeNone.
  • enabledRemoteNotificationTypes returns correct values.
  • Initially I used the method unregisterForRemoteNotifications on logout but I changed it to registerForRemoteNotificationTypes:UIRemoteNotificationTypeNone due to suspicians that this could be causing the problem .
  • This problem occurs in both development and adhoc builds and irrespectively of whether the app is installed via xcode or itunes.

Any thoughts and advices will be greatly appreciated. Thank you!

回答1:

This was happening to some of my devices. (Not showing up in notification center and not receiving pushes.)

Managed to fix it by doing:

  • Delete the app
  • Delete all the relevant profiles from the device. Settings app > General > Profiles, then tap into each of the Provisioning Profiles related to your app, then tap Remove. On iOS 8/9, where the setting no longer exists, use XCode > Windows > Devices > select device > Show provisioning profiles... > then remove the profile(s)
  • Turn your phone off, then on again.
  • Give 5 mins
  • Reinstall your app, the Provisioning Profile should get installed automatically.
  • Launch app and let it register and stuff.
  • Test push notifications again

For us, it didn't work immediately, so give it a few minutes.



回答2:

Maybe there is a problem with registering and unregistering the app at login/logout respectively, from Apple's documentation:

An application should register every time it launches and give its provider the current token.

And not sure about unregistering, they don't mention unregistering in their programming guide, maybe the app should never unregister and the server should handle that, by sending or not sending push notifications depending if the user is logged in or not. This is how I've done it in the past, and never experienced this issue, so maybe this approach works for you too.



回答3:

Well, I also have this problem, I found that as the application used the unregisterForRemoteNotifications before uninstall at the previous install.

And, in addition, if the application install again and login to register for the remote notifications, this problem will happen.

It happened also at the first install(installed after reset your iOS device). if you use the unregisterForRemoteNotifications before login, then register at the login operation, this problem will happen.

As this problem happened, you need to restart the iOS device.

For the unregisterForRemoteNotifications, we couldn't stop this problem, but we can reduce the probability of the occurrence of the problem, the method is:

If the device token didn't delete from provider at the previous install, then use unregisterForRemoteNotifications at the current install before login; Otherwise, you should never use unregisterForRemoteNotifications.