I'm trying to show the AlertView asking user to allow push notifications only when user clicks on a button.

I registered for push notifications in the button's action:

[[UIApplication sharedApplication] registerForRemoteNotifications];

And obviously, the Delegate methods related to push notifications are implemented in the appDelegate.

The problem is the alert of allowing push notification is appearing when launching the app despite I'm not registering in my appDelegate.

In fact, according to my knowledge, the alertView is not displayed only when I call registerForRemoteNotifications.

I'm missing something?

1 Answers 11

First you have to this code to register UIUserNotificationSettings.

UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound|UIRemoteNotificationTypeAlert) categories:nil];
[[UIApplication sharedApplication] registerUserNotificationSettings:settings];

When above code call this delegate method will call.

- (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings
{
    [application registerForRemoteNotifications];
}

Not the answer you're looking for? Browse other questions tagged or ask your own question.