Reputation: 187
I am trying to use Bluetooth of iPhone/iPad device from my app and search for near by devices within range and connect to the same.
Like non iOS phone or Mac within range it should show available devices and when tap needs to connect from the app.
I have tried below code using core bluetooth framework:
_centralManager = [[CBCentralManager alloc] initWithDelegate:self queue:nil];
_centralManager.delegate = self;
- (void)DidUpdateState:(CBCentralManager *)central
{
if (central.state != CBCentralManagerStatePoweredOn) {
return;
}
//start scanning
[self.centralManager scanForPeripheralsWithServices:nil options:nil];
}
but no delegates being called. I am running app on iPad 4 and I have LE Android phone (Bluetooth 4.0 LE compliant).
scanForPeripheralsWithServices:nil
I am setting nil
to show all available devices.
Upvotes: 0
Views: 1271
Reputation: 186
You will have to use [CBPeripheralManager].
After setting up delegate, fire [scanForPeripheralsWithServices:options:] Then in delegate method [didDiscoverPeripheral] you will get a name for each peripheral. Then you can show user a list of available devices and then use function connectPeripheral in CBCentralManager.
You can find great tutorial written in Objective-C here.
Upvotes: 2