简体   繁体   English

iPhone pushNotification DeviceToken-如何“解密”

[英]iPhone pushNotification DeviceToken - How to “decrypt”

I've already managed to get the devicetoken from APNs. 我已经设法从APNs获得devicetoken。 It's type of NSData. 这是NSData的类型。 So i want to write this deviectoken into my mysql db. 所以我想将此deviectoken写入我的mysql数据库中。 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. 如果我有可读格式的deviceToken。 How do i use the token in php to send a request to the apns server? 我如何在php中使用令牌向apns服务器发送请求?

thanks a lot! 非常感谢!

I added the following category to NSData 我将以下类别添加到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]; 然后我可以调用[devToken stringWithHexBytes]; and send that up to my server and store it as text. 并将其发送到我的服务器并将其存储为文本。

Hope that helps. 希望能有所帮助。

chris. 克里斯。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM