views:

600

answers:

2

In the iPhone Push Notification documentation, they have a code snippet in which they override the UIApplication method that receives a device token -

- (void)application:(UIApplication *)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)devToken {
const void *devTokenBytes = [devToken bytes];
self.registered = YES;
[self sendProviderDeviceToken:devTokenBytes]; // custom method
}

My question is, when I implement my own custom method, how do I use the devTokenBytes?

I need to create an HTTP Request, using NSURLConnection (I suppose), that will hand off the token to my server-side provider app. I get that part, but I'm not sure how to add devTokenBytes to the request? My first instinct was to use the bytes to create a String object, but when I try to using NSASCIIStringEncoding I get a weird jumbled mess of characters. I see that the return type of NSData's "bytes" method is a pointer, but I don't know what to do with it. What's the correct way to put this token into a request?

The documentation also details - "he application should connect with its provider and pass it this token, encoded in binary format." But I don't know how to handle something encoded in this manner.

+2  A: 

I haven't tried it out yet, but my first guess would be to look at Base64 encoding the binary array into a 7-bit clean string that can be passed as a query parameter on your request.

You could also POST the data to a URL instead, but I would think encoding it would be easier.

Eddie
A: 

Seems like the easiest way to handle this is to use the return value from the "description" method of NSData. It'll return a String that you can play with a bit to get a 64 character representation.

bpapa