0

this is my question:

I implemented this code for detected is user enabled or not Push Notification

if ([[UIApplication sharedApplication] isRegisteredForRemoteNotifications]) {
  NSLog(@"Yes, s(he) accepted Push Notification");
} else {
  NSLog(@"No, s(he) rejected Push Notification");
}

which, it works very well. But I had to implemented to receive silent Push Notification in background, so I added this code in my Info.plist

<key>UIBackgroundModes</key>
<array>
  <string>remote-notification</string>
</array>

Then, when I added this, the code that detected if user enabled or not Push notification always return TRUE, it doesn't matter if user enabled or not Push Notification. There is any way to detect only if the user enabled visible Push Notification (alerts in the top of the phone), allowing the UIBackgroundModes?

Mihriban Minaz
  • 3,043
  • 2
  • 32
  • 52
  • Possible duplicate of [Determine on iPhone if user has enabled push notifications](http://stackoverflow.com/questions/1535403/determine-on-iphone-if-user-has-enabled-push-notifications) – dan Mar 31 '16 at 16:04
  • It was not the same because it refers in general, but into comments is the solution... thanks @dan – Javier Landa-Torres Mar 31 '16 at 16:23

1 Answers1

0

Is not [[UIApplication sharedApplication] isRegisteredForRemoteNotifications] correct to use. To know the decision of the user about Push notification is with currentUserNotificationSettings

UIUserNotificationSettings *notificationSettings = [[UIApplication sharedApplication] currentUserNotificationSettings];

if (!notificationSettings || (notificationSettings.types == UIUserNotificationTypeNone)) {
      isEnabled = NO;
} else {
      isEnabled = YES;
}