I have my notes on Push Notification at https://github.com/onmyway133/notes/issues/219
π Scripts
These are the scenarios you can go through
isRegisteredForRemoteNotifications - UIApplication.shared.currentUserNotificationSettings
iOS 9.3.2 +
- Do not start push request dialog: false - none
- Enable push for the application when prompted for a request: true - warning, icon, sound
- Disable push for application: true - none
- Enable push, enable alert only: true - alert
- Uninstall and install again (within 24 hours): false - none
- Reject permission request: true - none
- Repeated press after failure: true - warning, icon, sound
π API
In iOS 8+, the Push Notification API was split into registerForRemoteNotifications and registerUserNotificationSettings .
So when you call registerForRemoteNotifications
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) is calledUIApplication.shared.isRegisteredForRemoteNotifications returns true
This means that the application receives a token-token and is ready to receive a push notification. Regardless of whether the OS supports the application prior to your application, it depends on the user notification settings , which the user switches to Settings
π Show me the code
To check if the push is enabled (means that the user can see the push message)
static var isPushNotificationEnabled: Bool { guard let settings = UIApplication.shared.currentUserNotificationSettings else { return false } return UIApplication.shared.isRegisteredForRemoteNotifications && !settings.types.isEmpty }
onmyway133
source share