How to register for push notifications on iOS 9 and above using Objective C?

I've been using the following code to register for remote notifications using Objective C.

Recently, after building and running the app on a testing device, an iPad mini running iOS 9.3.5, the Debugger Window no longer prints the device token. registerForRemoteNotificationTypes: is not supported in iOS 8.0 and later.

I am trying to use the device token to send a test notification using Sending Push Notifications Using Command-Line Tools


//REGISTER FOR THE NOTIFICATIONS TYPES

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions

{

    //-- Set Notification

    if ([application respondsToSelector:@selector(isRegisteredForRemoteNotifications)])

    {

        // iOS 8 Notifications

        [application registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]];

        [application registerForRemoteNotifications];

    }

    else

    {

        // iOS < 8 Notifications

        _storyBoard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];

        [[UIApplication sharedApplication] registerForRemoteNotificationTypes:

         (UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];

    }

    _storyBoard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];

    [[UIApplication sharedApplication] registerForRemoteNotificationTypes:

     (UIRemoteNotificationTypeSound | UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeAlert)];

    if (launchOptions != nil)

    {

        NSDictionary* dictionary = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];

        if (dictionary != nil)

        {

            NSLog(@"Launched from push notification: %@", dictionary);

            /*[self addMessageFromRemoteNotification:dictionary updateUI:NO];*/

        }

    }

    return YES;

}

I have also tried the following:

if (@available(iOS , *)) {
  // iOS 8 Notifications: Registering for notifications and types
    [application registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]];

    [application registerForRemoteNotifications];
} else {
// iOS < 8 Notifications
    _storyBoard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];

    [[UIApplication sharedApplication] registerForRemoteNotificationTypes:

     (UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];
}

And Xcode gives a parse error that says Expected a version of the form 'major[.minor[.subminor]]'

What is the correct way to register for push notifications on iOS 9 and above using Objective C?

Your problem is not with the Notifications API.

if (@available(iOS , *))

is incorrect. It should be in the form

if (@available(iOS 8, *))

After just testing the SSL Certificate again to connect using APNs using openssl s_client -connect api.sandbox.push.apple.com:443 -cert aps.cer -certform DER -key PushChatKey.pem -keyform PEM and a connections was made.

In the past week, I also used

curl -v --header 'apns-topic: com.faunna.PushChat' --header apns-push-type: alert --cert aps.cer --cert-type DER --key PushChatKey.pem --key-type PEM --data '{"aps":{"alert":"Hello From Faunna"}}' --http2  https://api.sandbox.push.apple.com/3/device/258ecf658e25256c8f06ddb1138d5d536ba0e760a96ebd12d3b1dbe112857c58

To send a test push notification to the test device.

I may submit a TSI to Apple.

How to register for push notifications on iOS 9 and above using Objective C?
 
 
Q