11

I added Push notifications to my application. And my application works based on push notifications. When the app runs for the first time, it is showing alert whether user wants to receive push notifications or not. Is it possible to make it mandatory to accept push notifications? Or if this is not possible, can we check whether push notifications are set for this app or not and terminate the application with alert?

Satyam
  • 15,493
  • 31
  • 131
  • 244

3 Answers3

22

You can only check whether user have selected to receive push-notifications:

UIRemoteNotificationType status = [[UIApplication sharedApplication] enabledRemoteNotificationTypes];
if (status == UIRemoteNotificationTypeNone)
{
    NSLog(@"User doesn't want to receive push-notifications");
}
Nekto
  • 17,837
  • 1
  • 55
  • 65
  • 4
    This is deprecated now. Should use isRegisteredForRemoteNotifications after iOS8. – woof Jun 12 '15 at 07:42
2

//It's better to use the followiing instead

BOOL status = [[UIApplication sharedApplication] isRegisteredForRemoteNotifications]; if (!status) { NSLog(@"User doesn't want to receive push-notifications"); }

Elsammak
  • 1,102
  • 10
  • 26
0

If your app target >= iOS 8.0 you can use:

UIApplication.sharedApplication().isRegisteredForRemoteNotifications()

as enabledRemoteNotificationTypes is deprecated.

Hossam Ghareeb
  • 7,063
  • 3
  • 53
  • 64