iPhone pushNotification DeviceToken - How to “decrypt”

喜夏-厌秋 提交于 2019-12-13 02:56:01

问题


I've already managed to get the devicetoken from APNs. It's type of NSData. So i want to write this deviectoken into my mysql db. I've already tried to convert it to a string without luck. That was my way:

 NSString *tokenTMP = [[NSString alloc] initWithData:devToken encoding:NSASCIIStringEncoding];

If i have the deviceToken in a readable format. How do i use the token in php to send a request to the apns server?

thanks a lot!


回答1:


I added the following category to NSData

- (NSString*) stringWithHexBytes 
{
   NSMutableString *stringBuffer = [NSMutableString stringWithCapacity:([self length] * 2)];
   const unsigned char *dataBuffer = [self bytes];

   for (int i = 0; i < [self length]; ++i)
   {
       [stringBuffer appendFormat:@"%02X", (unsigned long)dataBuffer[ i ]];
   }

   return [[stringBuffer retain] autorelease];
}

Then I can just call [devToken stringWithHexBytes]; and send that up to my server and store it as text.

Hope that helps.

chris.



来源:https://stackoverflow.com/questions/1929913/iphone-pushnotification-devicetoken-how-to-decrypt

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!