How can I determine when a user has ever seen a dialog asking for permission to push notifications (ios)

I am aware of enabledremotenotificationtypes, but that does not help me, because if I get enabledremotenotificationtypes == UIRemoteNotificationTypeNone, I will not be able to tell if user 1. received push notifications once, and then disabled it through installation later OR 2. rejected Push notifications OR 3. Never seen a blue dialog asking for permission. I need a way to differentiate these three cases.

Any help would be really appreciated.

+5
source share
2 answers

- , . registerUserNotificationSettings : . :

    //Request notification permission
UIUserNotificationSettings *notificationSettings = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | UIUserNotificationTypeSound categories:nil];
[[UIApplication sharedApplication] registerUserNotificationSettings:notificationSettings];

//Request notification permission again, but with a category with no actions
UIMutableUserNotificationCategory *category = [[UIMutableUserNotificationCategory alloc] init];
category.identifier = @"com.xyz.markNotificationPopupShownCategoryIdentifier";

UIUserNotificationSettings *notificationSettingsWithCategory = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | UIUserNotificationTypeSound categories:[NSSet setWithObject:category]];
[[UIApplication sharedApplication] registerUserNotificationSettings:notificationSettingsWithCategory];

allowRegisterUserNotificationSettings: (UIUserNotificationSettings *) notificationSettings , . 0, , :

if ([UIApplication sharedApplication].currentUserNotificationSettings.categories.count > 0) {
    NSLog(@"Notifications permissions has been asked");
} else {
    NSLog(@"Notifications permissions hasn't been asked");
}
+1

- - , , . int pushNotificationSeen. , pushNotificationSeen 1. , pushNotificationSeen 2. ​​ ( ):

-(void)saveData
{
if (self.pushNotificationSeen)
{
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    [defaults setInteger:self.pushNotificationSeen forKey:@"seen?"];
    [defaults synchronize];
}
}

viewDidLoad.

NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
self.pushNotificationSeen = [defaults integerForKey:@"seen?"];

, , , self.pushNotificationSeen 0, 1 2.

, - . , , .

-3

All Articles