【问题标题】:iPhone pushNotification DeviceToken - How to "decrypt"iPhone推送通知设备令牌-如何“解密”
【发布时间】:2009-12-18 18:27:46
【问题描述】:

我已经设法从 APN 获取 devicetoken。它是 NSData 的类型。 所以我想把这个 deviectoken 写到我的 mysql 数据库中。 我已经尝试将其转换为字符串,但没有运气。 那是我的方式:

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

如果我有可读格式的 deviceToken。如何使用 php 中的 token 向 apns 服务器发送请求?

非常感谢!

【问题讨论】:

    标签: php iphone encoding nsdata push-notification


    【解决方案1】:

    我在 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];
    }
    

    然后我可以调用 [devToken stringWithHexBytes];并将其发送到我的服务器并将其存储为文本。

    希望对您有所帮助。

    克里斯。

    【讨论】:

    • 感谢您的帮助。如果我想运行该应用程序,编译器会抱怨 ([self length] * 2) 出现错误“二进制操作数无效 *(具有 'id' 和 'int')”。
    • 我已经编辑了你的函数,现在它可以工作了!多谢! - (NSString*) stringWithHexBytes:(NSData *)token;像魅力一样工作:)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-11-23
    • 1970-01-01
    • 1970-01-01
    • 2011-12-30
    • 1970-01-01
    相关资源
    最近更新 更多