0

I'm using 'scanForPeripheralsWithServices' in iOS and successfully connecting to my intended device.

But Apple's documentation doesn't cover the case where no valid peripheral is found. What is the best practice for determining no peripherals are available, stopping the scan, and notify app users?

Brendenw
  • 785
  • 1
  • 6
  • 22

1 Answers1

0

You can achieve that using a NSTimer. And from the Bluetooth scanning (initializing) function, schedule that timer too.

@implementation YourClass
{
   NSTimer *timer;
}
- (void)startScan
{
   // Bluetooth related code
   timer = [NSTimer scheduledTimerWithTimeInterval:25 target:self selector:@selector(stopScan) userInfo:nil repeats:YES];
}

// Stops the Scanning and Timer
- (void)stopScan
{
   [yourCBCentralManager stopScan];
   [timer invalidate];
   timer = nil;
}

@end
Midhun MP
  • 103,496
  • 31
  • 153
  • 200
  • Great. I added a boolean variable to monitor if my desired peripheral was found in that time interval. – Brendenw Jan 17 '15 at 19:16