How to check if a user activated a push notification from settings?

This question is specific to iOS 10 APNS changes.

This is the flow of my application:

  • App installed
  • Starting applications ➝ Login screen
  • Successful login ➝ Start screen
  • Push Notification ➝ Request
  • Push Notification ➝ Do Not Allow
  • Close application
  • Settings ➝ Custom Push Push Notification
  • Open application
  • How to check if the settings are updated?
  • Close application
  • Settings ➝ User disabled Push Notification
  • Open application
  • How to check if the settings are updated?

I only request a push notification (step 4.) when the user logs in. This way, until the user logs out, I cannot re-request push.

Is there a clear solution for this so that we can support iOS 10 changes while still supporting iOS 8 or 9?

+5
source share
3 answers

use this code -

if ([[UIApplication sharedApplication] isRegisteredForRemoteNotifications]) { // yes }else{ // no } 
+6
source

UIUserNotificationSettings is deprecated in iOS8. If you want to access the general status of your application settings, check out UNUserNotifications, a new framework. I understand that he treats jerks and locals as one. When you register notifications, you can call to register. But for local permissions - icons, etc. You still need to request user permission. That is, your device can receive push notifications without user permission to receive data updates, but you can only show notifications through the center with permissions. Here's how to find out what permissions have been granted.

  • Import the framework into your class

     @import UserNotifications; 
  • Request settings

      - (void)_queryNotificationsStatus { UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter]; [center getNotificationSettingsWithCompletionHandler:^(UNNotificationSettings *settings){ //1. Query the authorization status of the UNNotificationSettings object switch (settings.authorizationStatus) { case UNAuthorizationStatusAuthorized: NSLog(@"Status Authorized"); break; case UNAuthorizationStatusDenied: NSLog(@"Status Denied"); break; case UNAuthorizationStatusNotDetermined: NSLog(@"Undetermined"); break; default: break; } //2. To learn the status of specific settings, query them directly NSLog(@"Checking Badge settings"); if (settings.badgeSetting == UNAuthorizationStatusAuthorized) NSLog(@"Yeah. We can badge this puppy!"); else NSLog(@"Not authorized"); }]; } 
+3
source

You can use currentUserNotificationSettings when your application comes to the fore.

  UIUserNotificationSettings *grantedSettings = [[UIApplication sharedApplication] currentUserNotificationSettings]; if (grantedSettings.types == UIUserNotificationTypeNone) { NSLog(@"No permiossion granted"); } else if (grantedSettings.types & UIUserNotificationTypeSound & UIUserNotificationTypeAlert ){ NSLog(@"Sound and alert permissions "); } else if (grantedSettings.types & UIUserNotificationTypeAlert){ NSLog(@"Alert Permission Granted"); } 

If you want to check if the status has changed from the previous one, you can save the previous value of currentUserNotificationSettings for some variable and compare it with the current value of overtime in the applicationWillEnterForeground method.

0
source

Source: https://habr.com/ru/post/1261829/


All Articles