iPhone pushNotification DeviceToken - Come "decifrare"
-
20-09-2019 - |
Domanda
Sono già riuscito a ottenere il token del dispositivo dagli APN.È di tipo NSData.Quindi voglio scrivere questo deviectoken nel mio db mysql.Ho già provato a convertirlo in una stringa senza fortuna.Questo era il mio modo:
NSString *tokenTMP = [[NSString alloc] initWithData:devToken encoding:NSASCIIStringEncoding];
Se ho il deviceToken in un formato leggibile.Come posso utilizzare il token in php per inviare una richiesta al server apns?
molte grazie!
Soluzione
Ho aggiunto la seguente categoria a NSData
- (NSString*) stringWithHexBytes
{
NSMutableString *stringBuffer = [NSMutableString stringWithCapacity:([self length] * 2)];
const unsigned char *dataBuffer = [self bytes];
for (int i = 0; i < [self length]; ++i)
{
[stringBuffer appendFormat:@"%02X", (unsigned long)dataBuffer[ i ]];
}
return [[stringBuffer retain] autorelease];
}
Quindi posso semplicemente chiamare [devToken stringWithHexBytes];e invialo al mio server e memorizzalo come testo.
Spero che aiuti.
Chris.
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow