iOS apps will get the deviceToken of the user push service from the APN server. The developer needs to actively bind the deviceToken to the mPaaS push service. During the test development, developers may need to perform message push testing via deviceToken, such as push testing of the Device dimension in the Mobile Push Service (MPS) console. In the MPS console, deviceToken is currently only accepted in hexadecimal string format. One way to obtain this string is as follows:
hexstring can be obtained by the following method for earlier version of //iOS 13
NSString *hexTokenString = [[deviceToken description] stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"<>"]];
hexTokenString = [hexTokenString stringByReplacingOccurrencesOfString:@" " withString:@""];
if ([hexTokenString length] > 0) {
NSLog(@"push DeviceToken is: %@",hexTokenString);
}
hexstring can be obtained by the following method for //iOS 13
NSUInteger dataLength = deviceToken.length;
if (dataLength == 0) {
return;
}
const unsigned char *dataBuffer = (const unsigned char *)deviceToken.bytes;
NSMutableString *hexTokenString = [NSMutableString stringWithCapacity:(dataLength * 2)];
for (int i = 0; i < dataLength; ++i) {
[hexTokenString appendFormat:@"%02x", dataBuffer[i]];
}
NSLog(@"push DeviceToken token:%@", hexTokenString);