来自(CBPeripheral *)aPeripheral的NSUUID到NSString

时间:2014-11-29 20:25:40

标签: objective-c cocoa bluetooth-lowenergy core-bluetooth

我想从CBPeripheral保存NSUUID的字符串版本。

我试试这个:

NSString *uuidString = aPeripheral.UUID;

但是会出现警告:

Incompatible pointer types initializing NSString with an expression of type CFUUIDRef

- (void) centralManager:(CBCentralManager *)central didConnectPeripheral:(CBPeripheral *)aPeripheral  {

    NSLog(@"method didConnectPeripheral %@ " , aPeripheral.UUID);

    NSString *uuidString = aPeripheral.UUID;
}

2 个答案:

答案 0 :(得分:1)

-UUID CBPeripheral方法返回CFUUIDRef,而不是NSString,自iOS 7.1起也不推荐使用。如果您需要使用它,请将其存储在CFUUIDRef中,或使用CFUUIDCreateString并将其桥接到NSString

答案 1 :(得分:1)

UUID不是字符串(即使它经常表示为字符串。)

您可以使用CFStringRef;

将其转换为CFUUIDCreateString()