iPhone pushNotification DeviceToken - 如何“解密” [英] iPhone pushNotification DeviceToken - How to "decrypt"
本文介绍了iPhone pushNotification DeviceToken - 如何“解密”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
所以我想把这个差异写入我的mysql数据库。
我已经尝试将它转换成字符串没有运气。
这是我的方式:
NSString * tokenTMP = [[NSString alloc] initWithData:devToken encoding:NSASCIIStringEncoding];
如果我有可读格式的deviceToken。如何使用php中的令牌向apns服务器发送请求?
非常感谢!
解决方案
我将以下类别添加到NSData
- (NSString *)stringWithHexBytes
{
NSMutableString * stringBuffer = [NSMutableString stringWithCapacity:([self length] * 2)];
const unsigned char * dataBuffer = [self bytes]; (int i = 0; i< [self length]; ++ i)
{
[stringBuffer appendFormat:@%02X,(unsigned long) dataBuffer [i]];
}
return [[stringBuffer retain] autorelease];
}
然后我可以调用[devToken stringWithHexBytes];并将其发送到我的服务器并将其存储为文本。
希望有帮助。
chris。 / p>
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!
解决方案
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.
这篇关于iPhone pushNotification DeviceToken - 如何“解密”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文