Я не могу найти официального способа вернуть строку UUID из CBUUID. Эти UUID могут иметь длину 2 или 16 байтов.
Цель состоит в том, чтобы сохранить CBUUID в файле где-нибудь в виде строки, а затем воскресить с помощью [CBUUID UUIDWithString:] и т. д. Вот что у меня есть до сих пор.
// 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?
}