Search code examples
macospush-notificationpushwoosh

How to convert NSData deviceToken to JSON-compatible string to remote API


I need to use the PushWoosh RemoteAPI to register my device. What is the recommended way to send the deviceIDToken as JSON to the service?

The DeviceID is a NSDATA, but to send it to the remote API I need to convert it to a string. Which encoding should I use?

NSString *tokenString = [[NSString alloc] initWithData:deviceToken encoding:NSASCIIStringEncoding];

Leads to strange data and is not accepted as a deviceToken.?


Solution

  • My app use this method below, I don't think it is a perfect way for it but it works

    NSString *strToken = [[deviceToken description] stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"<>"]] ;