Create a 128-bit UUID with a string

I tried to create 128Bit with iOS CoreBluetooth framework.

The code I wrote is here:

//16Bit Value-String static NSString * const ADVERTISING_SERVICE_16=@ "FFC0"; //Var for 128Bit String static NSString * ADVERTISING_SERVICE; //A Base UUID static NSString * const BASE_UUID=@ "0405060708090A0B0C0D0E0F"; + (NSString*) get128BitUUID:(NSString*)uuid{ return [[NSString alloc] initWithFormat:@"0000%@%@",uuid,BASE_UUID]; } ADVERTISING_SERVICE = [UUIDFuncs get128BitUUID:ADVERTISING_SERVICE_16]; 

And now when I try to get the UUID with this:

 if([service.UUID isEqual:[CBUUID UUIDWithString:ADVERTISING_SERVICE] ]){ [peripheral discoverCharacteristics:nil forService:service]; } 

I get this error message:

 2012-09-04 14:18:06.127 blukiiFirmwareTest[3154:707] *** Terminating app due to uncaught exception 'Invalid UUID string', reason: 'String 0000FFC00405060708090A0B0C0D0E0F does not represent a valid UUID' 

I do not understand why; the string is a 16-byte long UUID, it is 128 bits, so why am I getting this error?

+7
source share
1 answer

At the command prompt, enter uuidgen to create a new random uuid:

 0C50D390-DC8E-436B-8AD0-A36D1B304B18 

You will see that this is form 8-4-4-4-12, as mentioned on the wikipedia page, also associated with @PenguinCoder.

Creating a CBUUID with a string in this format will work:

 CBUUID *uuid = [CBUUID UUIDWithString:@"0C50D390-DC8E-436B-8AD0-A36D1B304B18"]; 
+19
source

All Articles