Ios CoreBluetooth-未为服务设置UUID

Ios CoreBluetooth-未为服务设置UUID,ios,objective-c,macos,uuid,core-bluetooth,Ios,Objective C,Macos,Uuid,Core Bluetooth,我尝试在mac和Iphone之间使用蓝牙。但是UUID似乎没有在mac上设置。我在mac上使用: self.characteristic = [[CBMutableCharacteristic alloc] initWithType:[CBUUID UUIDWithString:@"DDCA9B49-A6F5-462F-A89A-C2144083CA7F"] properties:CBCharacteristicPropertyNotify value:nil permissions:CBAt

我尝试在mac和Iphone之间使用蓝牙。但是UUID似乎没有在mac上设置。我在mac上使用:

 self.characteristic = [[CBMutableCharacteristic alloc] initWithType:[CBUUID UUIDWithString:@"DDCA9B49-A6F5-462F-A89A-C2144083CA7F"] properties:CBCharacteristicPropertyNotify value:nil permissions:CBAttributePermissionsReadable];

    self.service = [[CBMutableService alloc] initWithType:[CBUUID UUIDWithString:@"BA6878AE-4F70-41AD-B793-8F8AF2A2811E"] primary:YES];
    self.service.characteristics = @[self.characteristic];

    NSLog(@"UUID SERVICE : %@",self.service.UUID.description);//WTF ?
    [self.peripheralManager addService:self.service];
但是NSlog打印

UUID SERVICE : Unknown (<ba6878ae 4f7041ad b7938f8a f2a2811e>)
知道为什么服务的UUID没有在mac上正确设置吗

编辑:我使用

[外围启动转换:@{ CBAdvertisementDataLocalNameKey:@hello }];


在didAddServicemethod中;我可以找到[self.centralManager scan for peripheralswithservices:nil options:nil]的服务

我已经找到了解决方案,我只是非常愚蠢。服务广告不好

[外围启动转换:@{ CBAdvertisementDataServiceUUIDsKey: @[self.service.UUID]}


是一种很好的方法。

它似乎设置正确。它向您显示初始化它时使用的值。您确定吗?当我在Iphone上尝试相同的NSlog时,我得到了一些没有未知单词的东西:UUID服务:BA6878AE-4F70-41AD-B793-8f8af2a281ecorebluetooth在MacOS上的实现方式与在iOS上不同,尤其是CBUUID的描述方法不同。看看它打印出来的内容:ba6878ae 4f7041ad b7938f8a f2a2811e。这是您初始化时使用的UUID字符串。您何时公布服务?另外,如果您尝试[self.centralManager scan for peripheranswithservices:nil options:nil];您找到了吗?如果我使用[self.centralManager scan for experimentswithservices:nil options:nil];,我找到了。我在-void peripheraldmanager:cbperipheraldmanager*外围设备didAddService:CBService*服务错误:NSError*错误方法中公布服务
 self.serviceAlert = @"BA6878AE-4F70-41AD-B793-8F8AF2A2811E";

//add the services to the Array
self.services = [NSArray arrayWithObjects:
                 [CBUUID UUIDWithString:self.serviceAlert],
                 nil];

self.centralManager = [[CBCentralManager alloc] initWithDelegate:self queue:nil options:nil];

[self.centralManager scanForPeripheralsWithServices:self.services options:nil];