Como transformar o CBUUID em string
Não consigo encontrar nenhuma maneira oficial de obter uma string UUID de volta de um CBUUID. Esses UUIDs podem ter 2 ou 16 bytes de comprimento.
O objetivo é armazenar CBUUIDs em um arquivo em algum lugar como uma string, e depois ressuscitar com [CBUUID UUIDWithString:] etc. Aqui está o que eu tenho até agora.
// returns a simple 4 byte string for 16bit uuids, 128 bit uuids are in standard 8-4-4-4-12 format
// the resulting string can be passed into [CBUUID UUIDWithString:]
+(NSString*)CBUUIDToString:(CBUUID*)cbuuid;
{
NSData* data = cbuuid.data;
if ([data length] == 2)
{
const unsigned char *tokenBytes = [data bytes];
return [NSString stringWithFormat:@"%02x%02x", tokenBytes[0], tokenBytes[1]];
}
else if ([data length] == 16)
{
NSUUID* nsuuid = [[NSUUID alloc] initWithUUIDBytes:[data bytes]];
return [nsuuid UUIDString];
}
return [cbuuid description]; // an error?
}