iosapple-push-notificationsworklight-server

Device token not coming for iOS 9 device while integrating iOS native push notification with WorkLight


I am trying to send Push notification on iOS device via Worklight using sample code and steps provided at https://mobilefirstplatform.ibmcloud.com/tutorials/en/foundation/6.3/notifications/push-notifications-native-ios-applications/

When I run the app on iOS 7 device, i get a device token and therefore when i tap on subscribe button, i get a successful response. This works even if, when we don't write any code in didFinishLaunchingWithOptions for registeringForRemoteNotifications.

But When i run the same code on iOS 8 and iOS 9 device I am getting following message on console :

iOSNativePush[1119:372642] registerForRemoteNotificationTypes: is not supported in iOS 8.0 and later.

To make my application run for iOS>=8 device, I wrote following code :

  - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
 {
// Override point for customization after application launch.

if([[UIApplication sharedApplication] respondsToSelector:@selector(isRegisteredForRemoteNotifications)])
   {
    [[UIApplication sharedApplication] registerUserNotificationSettings:  [UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | UIUserNotificationTypeSound) categories:nil]];

    [[UIApplication sharedApplication] registerForRemoteNotifications];
    }
else
   {
    [[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIUserNotificationTypeAlert | UIUserNotificationTypeBadge |    UIUserNotificationTypeSound)];
   }
return YES;
   }


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

Still i am getting "iOSNativePush[1119:372642] registerForRemoteNotificationTypes: is not supported in iOS 8.0 and later" message in console but for iOS 8 device I am getting device token and device is getting subscribed but same thing is not working for iOS 9 device.

I refered following link also but no luck https://www.ibm.com/developerworks/community/blogs/worklight/entry/understanding-and-setting-up-push-notifications-in-development-evnironment?lang=en

Kindly help me to obtain device token for iOS 9 device.


Solution

  • if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0)
    {
        [[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]];
        [[UIApplication sharedApplication] registerForRemoteNotifications];
    }
    

    Use above code