报错原因:没有实现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);
}
}