0

I am trying to pass along the deviceToken I receive for IOS under didRegisterForRemoteNotificationsWithDeviceToken to another method which accepts NSDictionary which will further be sent to my backend Server as a POST request (JSON format).

I am able to convert the NSData format token to NSString but when I try to convert it to NSMutableDictionary I get a Null. Here is my Code:

- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *) deviceToken {

     NSLog(@"Entered didRegisterForRemoteNotification with token: %@", deviceToken);

     const unsigned *tokenBytes = [deviceToken bytes];
     NSString *hexToken = [NSString stringWithFormat:@"%08x%08x%08x%08x%08x%08x%08x%08x",
                      ntohl(tokenBytes[0]), ntohl(tokenBytes[1]), ntohl(tokenBytes[2]),
                      ntohl(tokenBytes[3]), ntohl(tokenBytes[4]), ntohl(tokenBytes[5]),
                      ntohl(tokenBytes[6]), ntohl(tokenBytes[7])];
// Token printed below looks good.
     NSLog(@"token in String format: %@",hexToken);

     NSMutableDictionary* myRegistrationData;
     [myRegistrationData setValue:hexToken forKey:@"deviceToken"];

     NSLog(@"sending token as NSMutableDictionary: %@",myRegistrationData);
            // the Dictionary with token printed here prints Null.

     [apiFromAppDelegate registerTokenWithAppServer:myRegistrationData];

}

Thanks in advance.

Curious101
  • 1,538
  • 2
  • 18
  • 36

0 Answers0