如何将一个64位字符串NSString反译回32bytes的NSData
NSString*newToken =@"fbf4082f57128dd1ed78986c6945dcf91519794b48c461af07a8e951180490de";
NSMutableData*apnsTokenMutableData = [[NSMutableData alloc]init];
unsigned charwhole_byte;
char byte_chars[3] = {'\0','\0','\0'};
int i;
for(i=0; i < [newToken length]/2; i++) {
byte_chars[0] = [newToken characterAtIndex:i*2];
byte_chars[1] = [newToken characterAtIndex:i*2+1];
// whole_byte =strtol(byte_chars,NULL,16);
charwhole_byte= strtol(byte_chars, NULL, 16);
[apnsTokenMutableData appendBytes:&charwhole_byte length:1];
}
NSData*apnsTokenData = [NSData dataWithData:apnsTokenMutableData];
NSLog(@"反译后=%@",apnsTokenData);
网友评论