我正在开发一个 iPhone 应用程序并尝试设置 Amazon SNS 以测试 PNS。当我们向 APNS 注册应用程序时,它会提供一个 32 位的设备令牌 (873DBDDA-17CF-4A24-88C6-990B90AFC4C3)。在向 Amazon SNS 注册设备时,它说设备令牌必须是 64 位长。我在这里想念什么?
问问题
7035 次
3 回答
11
你是怎么得到那个令牌的?它看起来不像是正确的 APNS 设备令牌。一个真正的将是64 个十六进制数字。这是我使用的代码:
-(void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
NSString *tokenstring = [[[deviceToken description]
stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"<>"]]
stringByReplacingOccurrencesOfString:@" " withString:@""];
// pass tokenstring to your APNS server
}
我从该方法中得到的令牌如下所示:
8ec3bba7de23cda5e8a2726c081be79204faede67529e617b625c984d61cf5c1
于 2014-01-03T23:39:55.950 回答
0
这是一个老问题,但我一直在寻找令牌的问题,但出现了这个悬而未决的问题。这是我使用的 - AWS v2。
- (void)awsStartWithDeviceToken:(NSData *)deviceToken {
// Get a hex string for the NSData deviceToken
// https://stackoverflow.com/questions/7520615/how-to-convert-an-nsdata-into-an-nsstring-hex-string
NSUInteger dataLength = [deviceToken length];
NSMutableString *deviceTokenString = [NSMutableString stringWithCapacity:dataLength*2];
const unsigned char *dataBytes = [deviceToken bytes];
for (NSInteger idx = 0; idx < dataLength; ++idx) {
[deviceTokenString appendFormat:@"%02x", dataBytes[idx]];
}
_savedDeviceTokenFormatted = deviceTokenString;
}
于 2015-01-02T03:55:36.953 回答
0
转换为十六进制字符串的 Swift 扩展
extension Data {
/// Return hexadecimal string representation of Data bytes
public var hexadecimalString: String {
var bytes = [UInt8](repeating: 0, count: count)
copyBytes(to: &bytes, count: count)
let hexString = NSMutableString()
for byte in bytes {
hexString.appendFormat("%02x", UInt(byte))
}
return String(hexString)
}
}
于 2016-09-16T11:16:19.637 回答