Iphone设备令牌 - NSData或NSString [英] Iphone device token - NSData or NSString

查看:160
本文介绍了Iphone设备令牌 - NSData或NSString的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在以 NSData 对象的形式接收iPhone设备令牌。
当我测试我的通知脚本功能时,我只从日志中复制了该对象并且通知正常。但是,当我现在尝试自动执行此操作时,我将设备令牌作为ASCII编码的字符串以变量的形式发送

I am receiving iPhone device token in the form of NSData object. When I tested my notifications script function, I have only copied that object from log and the notifications went fine. However when I try now to automatically do it, I am sending the device token as ASCII encoded string in the form of variable

self.deviceToken = [[NSString alloc] initWithData:webDeviceToken encoding:NSASCIIStringEncoding];

我得到的字符串有一些时髦的字符,看起来类似于 å-0¾fZÿ÷ʺÎUQüRáqEªfÔk«

The string that I am getting has some funky characters and looks similar to this "å-0¾fZÿ÷ʺÎUQüRáqEªfÔk«"

当服务器端脚本向该令牌发送通知时,我没有收到任何内容。

When server side script sends the notification to that token, I am not receiving anything.

我需要解码一些东西吗?

Do I need to decode something and how?

Regardz

推荐答案

好的,我找到了解决方案。如果有人有同样的问题,忘记ASCII编码,只需使用以下行生成字符串:

Ok, I found a solution. If anyone has the same problem, forget about ASCII encoding, just make the string with the following lines:

NSString *deviceToken = [[webDeviceToken description] stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"<>"]];
deviceToken = [deviceToken stringByReplacingOccurrencesOfString:@" " withString:@""];

这篇关于Iphone设备令牌 - NSData或NSString的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆