Iphone device token - NSData or NSString

前端 未结 6 1541
走了就别回头了
走了就别回头了 2020-12-13 13:38

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 th

6条回答
  •  -上瘾入骨i
    2020-12-13 14:31

    Another way of converting device token into hexa decimal string

    NSUInteger capacity = [deviceToken length] * 2;
    NSMutableString *stringBuffer = [NSMutableString stringWithCapacity:capacity];
    const unsigned char *dataBuffer = [deviceToken bytes];
    NSInteger i;
    for (i=0; i<[deviceToken length]; ++i) {
        [stringBuffer appendFormat:@"%02X", (NSUInteger)dataBuffer[i]];
    }
    NSLog(@"token string buffer is %@",stringBuffer);
    

提交回复
热议问题