且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

通过Java使用苹果推送通知服务

更新时间:2023-01-20 13:10:33

只是一个小尖,为了您收到的令牌转换为​​适合与javapns登记的格式,这code将这样的伎俩:

Just a little tip, in order to convert your received token into a format suitable for registration with javapns, this code will do the trick:

- (NSString *)convertTokenToDeviceID:(NSData *)token {
NSMutableString *deviceID = [NSMutableString string];

// iterate through the bytes and convert to hex
unsigned char *ptr = (unsigned char *)[token bytes];

for (NSInteger i=0; i < 32; ++i) {
	[deviceID appendString:[NSString stringWithFormat:@"%02x", ptr[i]]];
}

return deviceID;

}