0

I am implementing remote notifications in one of my applications and for getting the device token i am using the method.

  - (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
    NSLog(@"Did Register for Remote Notifications with Device Token (%@)", deviceToken);
    NSString * token = [NSString stringWithFormat:@"%@", deviceToken];
    //Format token as you need:
    token = [token stringByReplacingOccurrencesOfString:@" " withString:@""];
    token = [token stringByReplacingOccurrencesOfString:@">" withString:@""];
    token = [token stringByReplacingOccurrencesOfString:@"<" withString:@""];

   // [OTWebServiceHelper sharedInstance].deviceTocken    = token;
    NSLog(@"App Token for Device%@",token);
    [[NSUserDefaults standardUserDefaults] setObject:token forKey:@"MyAppDeviceToken"];
    [[NSUserDefaults standardUserDefaults] synchronize];

}

It works fine when i am checking the 8.0 devices but in ios 9.3.1 it is not getting called.

I referred this link but of no use.

didRegisterForRemoteNotificationsWithDeviceToken is not called up in ios 9

Please help me.

For registering i am using the code:

  -(void)registerForPUSHNotifications {

    NSString *iOSversion = [[UIDevice currentDevice] systemVersion];
    NSString *prefix = [[iOSversion componentsSeparatedByString:@"."] firstObject];
    float versionVal = [prefix floatValue];


    if (versionVal >= 8)
    {
        //for iOS8
        UIUserNotificationSettings *settings =
        [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert |
         UIUserNotificationTypeBadge |
         UIUserNotificationTypeSound categories:nil];
        [[UIApplication sharedApplication] registerUserNotificationSettings:settings];
        [[UIApplication sharedApplication] registerForRemoteNotifications];
    }
    else
    {

        [[UIApplication sharedApplication] registerForRemoteNotificationTypes: (UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];

    }
}
Community
  • 1
  • 1
Ashley Rodrigues
  • 153
  • 2
  • 10

0 Answers0