小编Gin*_*ina的帖子

iOS Core Bluetooth:在外围设备上未发现广告服务

在连接到广告我感兴趣的特定服务的BLE设备之后,为了发现这项服务,我打电话给:

[self.peripheral discoverServices:@[[self.class serviceUUID]]];
Run Code Online (Sandbox Code Playgroud)

该- (void)peripheral:(CBPeripheral *)peripheral didDiscoverServices:(NSError *)error委托方法被调用,没有错误,但在外围返回服务的数量为0,因此没有特性进一步发现.有谁知道为什么会这样?提前致谢!

以下是委托方法的完整主体.

- (void)peripheral:(CBPeripheral *)peripheral didDiscoverServices:(NSError *)error {
    if (error) {
        NSLog(@"didDiscoverServices failed: %@", error);
        return;
    }

    NSLog(@"didDiscoverServices succeeded for peripheral: %@.", peripheral.name);
    NSLog(@"Number of services: %d", peripheral.services.count);

    for (CBService *s in peripheral.services) {
        NSLog (@"Discovered service UUID: %@", s.UUID);
        if ([s.UUID isEqual:[self.class serviceUUID]]) {
            NSLog(@"Discover characteristics...");
            [self.peripheral discoverCharacteristics:@[[self.class controlPointCharacteristicUUID], [self.class packetCharacteristicUUID]] forService:s];
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

控制台显示:

2014-11-27 15:54:51.933 k[197:13362] didDiscoverServices succeeded for peripheral: BootK
2014-11-27 15:54:51.934 k[197:13362] Number of …
Run Code Online (Sandbox Code Playgroud)

xcode objective-c ios core-bluetooth cbperipheral

5
推荐指数
1
解决办法
913
查看次数

标签 统计

cbperipheral ×1

core-bluetooth ×1

ios ×1

objective-c ×1

xcode ×1