Discovering services for peripheral while delegate is either nil or does not implement(ios蓝牙)

报错原因:没有实现peripheral代理方法1

调用方法

- (void)discoverIncludedServices:(nullable NSArray<CBUUID *> *)includedServiceUUIDs forService:(CBService *)service;

才会需要实现peripheral代理方法2

//peripheral代理方法1
-(void)peripheral:(CBPeripheral *)peripheral didDiscoverServices:(NSError *)error{
    NSLog(@"搜到%d个服务",_i++);
       for (CBService *service in peripheral.services) {
           NSLog(@"Discovered service %@",service);
       }
}

//peripheral代理方法2
- (void)peripheral:(CBPeripheral *)peripheral didDiscoverIncludedServicesForService:(CBService *)service error:(NSError *)error{
    //这个方法并不会被调用,而且如果不实现peripheral代理方法1会报下面的错误
//API MISUSE: Discovering services for peripheral while delegate is either nil or does not implement peripheral:didDiscoverServices:
    NSLog(@"搜到%d个服务代理二",_i++);
    for (CBService *service in peripheral.services) {
        NSLog(@"Discovered service %@",service);
    }
}
已标记关键词 清除标记
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页