Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to know if the push notification permission alert has already been shown

Tags:

I want to implement a custom screen that informs my users why I'm about to ask for push notification permissions. After they press a button in that custom screen I present the iOS push notification permission dialog with [[UIApplication sharedApplication] registerForRemoteNotificationTypes:

I only want to show this custom screen once if the user hasn't already seen the push notification permission dialog. I cannot use [[UIApplication sharedApplication] enabledRemoteNotificationTypes] == UIRemoteNotificationTypeNone as this will also return 'none' if the user decided to not allow push notifications.

Any ideas anyone?

like image 701
Jovan Avatar asked Aug 12 '14 12:08

Jovan


People also ask

Where does a push notification appear?

Push notification alerts can be displayed in three locations on your phone—lock screen, banner, and notification center, when the app user opts-in for messages.

How do I know if I have push notifications on my Iphone?

Go to Settings and tap Notifications. Select an app under Notification Style. Under Alerts, choose the alert style that you want. If you turn on Allow Notifications, choose when you want the notifications delivered — immediately or in the scheduled notification summary.

What happens when you turn on push notifications?

Push notifications are messages that pop up on a user's mobile phone or desktop device via their chosen web browser. These little banners slide into view — whether or not your app or website is open.


1 Answers

You could use NSUserDefaults :

#define kPushNotificationRequestAlreadySeen @"PushNotificationRequestAlreadySeen"  if(![[NSUserDefaults standardUserDefaults] boolForKey:kPushNotificationRequestAlreadySeen]) {      // Notify the user why you want to have push notifications     UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:... delegate:self ...];     [alertView show];      [[NSUserDefaults standardUserDefaults] setBool:YES forKey:kPushNotificationRequestAlreadySeen]; } else {     // Already allowed -> register without notifying the user     [[UIApplication sharedApplication] registerForRemoteNotificationTypes:UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound]; } 

And

- (void)alertView:(UIAlertView*)alertView didDismissWithButtonIndex:(NSInteger)index {     // Actually registering to push notifications     [[UIApplication sharedApplication] registerForRemoteNotificationTypes:UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound]; } 
like image 174
matt.P Avatar answered Sep 23 '22 08:09

matt.P