在iOS7下,主要的ANCS服务是要不断发布的,还是需要在混淆的设置中启用/是否需要使用自定义的CBPeripheralManager(使用Apple指定的服务和特征性UUID)在自定义CBPeripheralManager中实现,才能使潜在的通知使用者成功发现它并订阅?

Apple文档(CoreBluetooth Programming GuideANCS Specification)都令人惊讶地失去了与此有关的任何信息。他们似乎暗示需要自定义实现,但这只是我们的猜想。

给定主要的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];

最佳答案

作为对这个问题的迟来的回答,既然小牛队已经退出了,这就是我们要提出的。

我们最初在两台iOS设备之间实现ANCS规范的努力没有成功,其中一台被称为Peripheral,一台被称为Central。苹果过了一会儿对我们做出了回应(向他们的传福音者致敬),并告诉我们这是不可能的。

通过向OSX Mavericks上的IOBluetooth.framework中嵌入的CoreBluetooth.framework添加CBPeripheralManager类和CBPeripheralManagerDelegate协议(protocol)(深呼吸),我们现在可以在OSX设备上使用BLE radio 实现和通告ANCS。

因此,此代码段属于OSX上的CBPeripheralManager:

- (void) advertiseANCS
{
    NSLog(@"%s", __FUNCTION__);

    // 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:@"ANCS" forKey:CBAdvertisementDataLocalNameKey];
    [advertisementData setValue:@[ANCSUUID] forKey:CBAdvertisementDataServiceUUIDsKey];

    // publish the ANCS service
    [self.peripheralManager addService:ANCS];
    [self.peripheralManager startAdvertising:advertisementData];
}

而此代码段属于iOS设备上的CBCentralManager:
- (void) discoverANCS
{
    NSLog(@"%s", __FUNCTION__);

    NSMutableArray *services = [NSMutableArray array];
    [services addObject:@"7905F431-B5CE-4E99-A40F-4B1E122D00D0"];

    NSMutableDictionary *options = [NSMutableDictionary dictionary];
    [options setValue:[NSNumber numberWithBool:NO] forKey:CBCentralManagerScanOptionAllowDuplicatesKey];

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

iOS设备现在可以查看并连接到OSX radio ,该 radio 实现了Apple文档中详细介绍的ANCS规范。
<CBCentralManager: 0x14e23280> <CBPeripheral: 0x14d27b40 identifier = 7231B80F-874E-DB5F-2AF9-7F376911E2B7, Name = "ANCS", state = disconnected> {
    kCBAdvDataChannel = 39;
    kCBAdvDataIsConnectable = 1;
    kCBAdvDataLocalName = ANCS;
} -60

狩猎愉快

关于objective-c - iOS 7 ANCS : Discovering the primary ANCS Service UUID,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/19118699/

10-12 23:26