Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Push Notification ON or OFF Checking in iOS

Tags:

I want to check "Push Notification option" in iOS device, any time if the application is running (or ON from resume mode). I use the following code to check, if the option is OFF:

-(void)PushNotificationServiceChecking {     UIRemoteNotificationType types = [[UIApplication sharedApplication] enabledRemoteNotificationTypes];      if (types == UIRemoteNotificationTypeNone)     {         NSString *msg = @"Please press ON to enable Push Notification";         UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Push Notification Service Disable" message:msg delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"ON", nil];         alert.tag = 2;         [alert show];     } } 

Then i use the following code for going to the "Settings tab >> Notification center", so that user can on it manually :

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {     if (alertView.tag == 2)     {         if (buttonIndex == 0)         {             // this is the cancel button         }         else if (buttonIndex == 1)         {             [[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge|UIRemoteNotificationTypeSound|UIRemoteNotificationTypeAlert)];         }     }  } 

But, now the problem that I am facing is, it only appears at the 1st time after launching the application. It works as I want. But after that, if I turn OFF the "Push Notification option" from "settings" it gives me no "Alert Message".

like image 500
Tulon Avatar asked Dec 04 '13 11:12

Tulon


People also ask

Should I allow push notifications on my iPhone?

If you allow notifications on your iPhone from every app you use, you may spend more time checking your notifications than getting things done. While some notifications can be very important – phone calls and text messages, for example – too many notifications is bad for our sanity.

What happens if I turn off push notifications?

Nothing will interrupt you, but all the notifications will still appear when you pull down the windowshade. On Android, you can choose "Show Silently," a similar setup. It's not like turning off notifications shuts you out from using the apps you like.

How do I know if push notifications are on iPhone?

Find your notifications in Notification CenterOn the Lock Screen: Swipe up from the middle of the screen. On other screens: Swipe down from the top center. Then you can scroll up to see older notifications, if there are any.

Should I turn off push notifications?

Well, science is here to save the day (as always) with one simple answer: disable all notifications. A study from Carnegie Mellon University and Telefonica suggests that using your smartphone sans notifications for a mere 24-hour period can noticeably improve your concentration, as well as reduce your stress levels.


1 Answers

In iOS 8 you can now use:

[[UIApplication sharedApplication] isRegisteredForRemoteNotifications]; 

And to check how the settings are setup you could use:

[[UIApplication sharedApplication] currentUserNotificationSettings]; 
like image 99
thijsai Avatar answered Oct 03 '22 08:10

thijsai