Why it is recommended to register registerUserNotificationSettings before registering using the push notification service

I was going to use the new iOS 8 remote notification API when I found this in the docs:

"It is recommended that you use this method before you plan local notifications or register with the push notification service."

I could not understand why this is so. I get the impression that two methods are calling:

registerUserNotificationSettings

and

registerForRemoteNotifications

are now independent, while others are not functioning. Then why is it recommended to call one by one?

+4
source share
2 answers

You can find this in the Apple documentation:

, , , , registerUserNotificationSettings:, , . , .

0

IOS 8, , .

if (IS_OS_8_OR_LATER) {

        //Right, that is the point
        UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:(UIRemoteNotificationTypeBadge
                                                                                             |UIRemoteNotificationTypeSound
                                                                                             |UIRemoteNotificationTypeAlert) categories:nil];
        [[UIApplication sharedApplication] registerUserNotificationSettings:settings];
    }else{
        // Register for push notifications
        [application registerForRemoteNotificationTypes:
         UIRemoteNotificationTypeBadge |
         UIRemoteNotificationTypeAlert |
         UIRemoteNotificationTypeSound];
    }

///////////

#ifdef __IPHONE_8_0
- (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings
{
    //register to receive notifications
    [application registerForRemoteNotifications];
}

- (void)application:(UIApplication *)application handleActionWithIdentifier:(NSString *)identifier forRemoteNotification:(NSDictionary *)userInfo completionHandler:(void(^)())completionHandler
{
    //handle the actions
    if ([identifier isEqualToString:@"declineAction"]){
    }
    else if ([identifier isEqualToString:@"answerAction"]){
    }
}

ios 8

-1

All Articles