在 iOS7 下,主要的 ANCS 服务是要不断宣传的,还是需要在模糊设置中启用/使用自定义 CBPeripheralManager(使用 Apple 指定的服务和特征 UUID)实现,以便潜在的通知消费者成功发现它并订阅?
Apple 文档(CoreBluetooth 编程指南和ANCS 规范)出人意料地没有关于这方面的任何信息。他们似乎暗示需要自定义实现,但这只是我们的推测。
给定主要的 ANCS 服务 UUID: 7905F431-B5CE-4E99-A40F-4B1E122D00D0
,执行扫描不会产生任何命中。正如预期的那样,扫描整个 BLE 频谱会产生对其他 BLE 设备的命中,但不会对单个 ANCS 设备产生命中。
编辑 1:
定义自定义 CBPeripheralManager 并手动添加 Apple 指定的 ANCS 服务及其相关特性失败,并出现 NSError:Error Domain=CBErrorDomain Code=8 "The specified UUID is not allowed for this operation."
因此,服务 UUID 似乎是由 Apple 保留的(应该如此),我们无法以这种方式启用它。
非常感谢任何见解;我们已经就此与 Apple 联系,并会在收到他们的消息后进行更新。
下面的代码重现了上面提到的 NSError:
// define the ANCS Characteristics
CBUUID *notificationSourceUUID = [CBUUID UUIDWithString:@"9FBF120D-6301-42D9-8C58-25E699A21DBD"];
CBMutableCharacteristic *notificationSource = [[CBMutableCharacteristic alloc] initWithType:notificationSourceUUID properties:CBCharacteristicPropertyNotifyEncryptionRequired value:nil permissions:CBAttributePermissionsReadEncryptionRequired];
CBUUID *controlPointUUID = [CBUUID UUIDWithString:@"69D1D8F3-45E1-49A8-9821-9BBDFDAAD9D9"];
CBMutableCharacteristic *controlPoint = [[CBMutableCharacteristic alloc] initWithType:controlPointUUID properties:CBCharacteristicPropertyWrite value:nil permissions:CBAttributePermissionsWriteEncryptionRequired];
CBUUID *dataSourceUUID = [CBUUID UUIDWithString:@"22EAC6E9-24D6-4BB5-BE44-B36ACE7C7BFB"];
CBMutableCharacteristic *dataSource = [[CBMutableCharacteristic alloc] initWithType:dataSourceUUID properties:CBCharacteristicPropertyNotifyEncryptionRequired value:nil permissions:CBAttributePermissionsReadEncryptionRequired];
// define the ANCS Service
CBUUID *ANCSUUID = [CBUUID UUIDWithString:@"7905F431-B5CE-4E99-A40F-4B1E122D00D0"];
CBMutableService *ANCS = [[CBMutableService alloc] initWithType:ANCSUUID primary:YES];
ANCS.characteristics = @[notificationSource, controlPoint, dataSource];
// define the Advertisement data
NSMutableDictionary *advertisementData = [NSMutableDictionary dictionary];
[advertisementData setValue:@"CUSTOM_ANCS" forKey:CBAdvertisementDataLocalNameKey];
[advertisementData setValue:@"7905F431-B5CE-4E99-A40F-4B1E122D00D0" forKey:CBAdvertisementDataServiceUUIDsKey];
// publish the ANCS service
[self.peripheralManager addService:ANCS];