Question

I have a navigation controller that has a root view controller and two tableview controllers. When I push the first tableview controller onto the stack, cbcentralmanager scans for BLE peripherals, and everything works great. However, when I push the second tableview controller onto the stack, and then pop it off (going back to the first tableview controller), cbcentralmanager scans, but no devices are discovered. Here is the code of that first tableview controller. The viewWillAppear method is being called as expected each time the tableview controller is displayed, but the scan reveals nothing.

- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];

[AppDelegate app].cbCentral.delegate = self;
[AppDelegate app].peripheral.delegate = self;
[AppDelegate app].brspObject.delegate = self;

peripherals = [NSMutableArray new];
[self startScan];
}

- (void)startScan
{    
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
[peripherals removeAllObjects];
[self.tableView reloadData];

[[AppDelegate app].cbCentral scanForPeripheralsWithServices:[NSArray arrayWithObject:[Brsp brspServiceUUID]] options:nil];

[self performSelector:@selector(stopScan) withObject:nil afterDelay:5.0];
}

I have been stumped by setting proper delegates in the past, but I think I have all my bases covered here. Any thoughts?

Was it helpful?

Solution

I'm not sure why this worked, but I moved these lines of code:

[AppDelegate app].cbCentral.delegate = self;
[AppDelegate app].peripheral.delegate = self;
[AppDelegate app].brspObject.delegate = self;

to the -(void)startScan method, and now it works.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top