As you see in the apple web site, you should encode the device token in binary format. And the device token must be in network order (
that is, big endian order).

Actually, it's easy but U need to make sure it's in big endian order. Here U needn't consider the binary order in this simple way. I use it in my PUSH sender process.
/************************************
* Tools as :
* string to hex binary
***********************************/
inline uint8_t hex_int_value(char in);
uint8_t get_hex_value(char in_1, char in_2);
int get_device_token_binary(const char *token, char *binary)
{
uint8_t a;
char *p = (char*)token;
char *r = binary;
for(int i = 0; i < 64; i += 2) {
if (isxdigit(*(p+i)) == 0 || isxdigit(*(p+i+1)) == 0) {
return -1;
}
a = get_hex_value(*(p+i), *(p+i+1));
memcpy(r++, &a, sizeof(uint8_t));
}
return 0;
}
uint8_t get_hex_value(char in_1, char in_2)
{
uint8_t value = 0;
uint8_t val_high = hex_int_value(in_1);
uint8_t val_low = hex_int_value(in_2);
return val_high * 16 + val_low;
}
inline uint8_t hex_int_value(char in)
{
if (in >= '0' && in <= '9') {
return (in - '0');
} else if (in >= 'a' && in <= 'f') {
return (in - 'a' + 10);
} else {
return 0;
}
}
If you find sth wrong or some better way, pls tell me. Thx.