iOS 7 ANCS:发现主要的ANCS服务UUID [英] iOS 7 ANCS: Discovering the primary ANCS Service UUID

查看:804
本文介绍了iOS 7 ANCS:发现主要的ANCS服务UUID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在iOS7下,主要的ANCS服务是否需要不断广告,或是否需要在模糊设置中启用/使用自定义CBPeripheralManager(使用Apple指定的服务和特性UUID)为潜在的通知消费者实现成功发现并订阅?

Under iOS7, is the primary ANCS Service meant to be constantly advertised, or does it need to be enabled in obfuscated settings / implemented using a custom CBPeripheralManager (using the Apple-specified Service and Characteristic UUIDs) for a potential Notification Consumer to successfully discover it and subscribe?

Apple文档( CoreBluetooth编程指南,以及 ANCS规范令人惊讶地失去了关于此的任何信息。他们似乎暗示要求自定义实现,但这只是我们的推测。

The Apple documentation (both the CoreBluetooth Programming Guide, and the ANCS Specification) are surprisingly bereft of any information on this. They seem to hint at requiring a custom implementation, but this is just conjecture on our part.

给定主要ANCS服务UUID: 7905F431-B5CE -4E99-A40F-4B1E122D00D0 ,执行扫描不会产生命中。按预期扫描整个BLE频谱会产生其他BLE设备的命中,但不会产生单个ANCS设备。

Given the primary ANCS Service UUID: 7905F431-B5CE-4E99-A40F-4B1E122D00D0, performing a scan yields no hits. Scanning the entire BLE spectrum, as expected, yields hits for other BLE devices, but not a single ANCS device.

编辑1

定义自定义CBPeripheralManager并手动添加Apple指定的ANCS服务及其关联特性失败,出现NSError:错误域= CBErrorDomain代码= 8此操作不允许指定的UUID。

Defining a custom CBPeripheralManager and manually adding the Apple-specified ANCS Service with its associated Characteristics fails, with the NSError: Error Domain=CBErrorDomain Code=8 "The specified UUID is not allowed for this operation."

因此,似乎Apple保留了服务UUID(因为它应该是),我们无法以这种方式启用它。

Consequently, it appears that the Service UUID is reserved by Apple (as it should be), and we cannot enable it in this manner.

非常感谢任何见解;我们已经向Apple联系了这个问题,并会在收到回复的时候更新。

Any insight is greatly appreciated; we've reached out to Apple about this, and will update when we hear from them.

下面的代码重现了上面提到的NSError:

The code below reproduces the NSError mentioned above:

// 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];


推荐答案

作为这个问题的迟来的答案,现在是小牛队好了,这就是我们想出来的。

As a belated answer to this question, now that Mavericks is out, here is what we've come up with.

我们最初在两个iOS设备之间实现ANCS规范的努力,其中一个是作为Central的外围产品,但未成功。过了一段时间后,Apple回复了我们(给他们的福音传道者提示)并且告诉我们这是不可能的。

Our initial efforts to implement the ANCS specification between two iOS devices, one as Peripheral one as Central, were unsuccessful. Apple responded to us after some time (hat tip to their evangelists) and told us this was impossible.

在CoreBluetooth中添加了CBPeripheralManager类和CBPeripheralManagerDelegate协议。在OSX Mavericks上嵌入IOBluetooth.framework的框架(深呼吸),我们现在可以在OSX设备上使用BLE无线电来实现和宣传ANCS。

With the addition of the CBPeripheralManager class and CBPeripheralManagerDelegate protocol to the CoreBluetooth.framework embedded in the IOBluetooth.framework on OSX Mavericks (deep breath), we can now use the BLE radio on an OSX device to implement and advertise ANCS.

因此,这个snippet属于OSX上的CBPeripheralManager:

Thus, this snippet belongs to a CBPeripheralManager on OSX:

- (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:

Whereas this snippet belongs on a CBCentralManager on an iOS device:

- (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无线电,实现了Apple文档中详述的ANCS规范。

The iOS device can now see and connect to the OSX radio, which implements the ANCS specification as detailed in the Apple documentation.

<CBCentralManager: 0x14e23280> <CBPeripheral: 0x14d27b40 identifier = 7231B80F-874E-DB5F-2AF9-7F376911E2B7, Name = "ANCS", state = disconnected> {
    kCBAdvDataChannel = 39;
    kCBAdvDataIsConnectable = 1;
    kCBAdvDataLocalName = ANCS;
} -60

快乐狩猎

这篇关于iOS 7 ANCS:发现主要的ANCS服务UUID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆