Corebluetooth method scanForPeripheralsWithService

2019-05-17 18:07发布

问题:

I am working on bluetooth related app.but i didn't get any success.

in my app i want to connect my iDevice with any other bluetooth device who is scanning.

but with CBCentralManager method scanForPeripheralsWithServices , i didn't get any response in didDiscoverPeripheral method.

CBCentralManager alloc method here :-

(void)viewDidLoad
    {
        [super viewDidLoad];

        // Start up the CBCentralManager
        _centralManager = [[CBCentralManager alloc] initWithDelegate:self queue:nil];

        _textview.userInteractionEnabled = NO; // not used in this test app
    }

Scanning method for CBCentralManager :-

(void)scanForPeripherals {
    if (self.centralManager.state != CBCentralManagerStatePoweredOn) {
        NSLog(@"CBCentralManager must be powered to scan peripherals. %d", self.centralManager.state);
        return;
    }

    if (self.scanning) {
        return;
    }

    self.scanning = YES;

    [self.centralManager scanForPeripheralsWithServices:nil options:@{ CBCentralManagerScanOptionAllowDuplicatesKey: @YES }];
    NSLog(@"Scanning started");
}

but i never receive any response in didDiscoverPeripheral method.can any one help me with this code.?