Vidhyanand
Vidhyanand

Reputation: 5369

Retrieve paired devices which are connected through bluetooth in iOS

I have connected Barcode Scanner device

Barcode Scanner Information

I want to know the paired status of it. Whether it is connected with device or not.

- (void) centralManager:(CBCentralManager *)central didDiscoverPeripheral:(CBPeripheral *)peripheral advertisementData:(NSDictionary *)advertisementData RSSI:(NSNumber *)RSSI
    {
        self.connectingPeripheral = peripheral;        
        NSLog(@"@@@@@@Peripheral Name is:%@ Identifier:%@ Services:%@",peripheral.name,peripheral.identifier,peripheral.services);
        [self.bluetoothManager connectPeripheral: self.connectingPeripheraloptions: nil];
}

Paired List

I am getting information about Mac's which are nearby and enabled. But I am not getting Barcode Scanner information in this Method.

I need whether barcode scanner is connected to device or not.

can anyone suggest how to find connectivity of barcode scanner.

I appreciate your response, Thanks.

Upvotes: 11

Views: 10806

Answers (3)

Vikas Dadheech
Vikas Dadheech

Reputation: 1720

Read the below answer:

https://stackoverflow.com/a/11128869/5178107

Might help you. More over, CoreBluetooth only allows you to access Bluetooth Low Energy devices. You can pair these devices if you need encryption but typically you don't. However, there is no API to list the paired devices - you need to discover the device(s) that are offering the service you are interested in and present a list, if necessary using your own UI in your app. Once you have identified the target device you can initiate a connection.

Upvotes: 4

wj2061
wj2061

Reputation: 6885

  1. The Settings App can discover nearly all kinds of bluetooth devices,but the system only notify your app for BLE devices.
    Reboot your Scanner , and make sure your iPhone and Scanner are not connected with any devices.Enable your Scanner's discoverabilty.
    If Settings App can find the Scanner while your demo are not,the Scanner is not a BLE device, and is not supported by iOS since iPhone 4s.

  2. If the Scanner is a BLE device,there are some extra work to do to figure out if they are connected.

    • You can check the state of the discovered CBPeripheral in func centralManager(_ central: CBCentralManager, didDiscoverPeripheral peripheral: CBPeripheral, advertisementData advertisementData: [String : AnyObject], RSSI RSSI: NSNumber) .

    • Store CBPeripheral's identifier,before you connect to it.Use this identifier in func retrievePeripheralsWithIdentifiers(_ identifiers: [NSUUID]) -> [CBPeripheral].And check if your Scanner is in the return Array.

If you don't store the identifier,there is no way that you can access an connected BLE Device.

Upvotes: 3

Eirik M
Eirik M

Reputation: 816

As mentioned in the comments, Core Bluetooth is for Bluetooth low energy, while the bar code scanner is Bluetooth 2.1 (classic). For this to work you have to use IOBluetooth at the very least.

Check the IOBluetooth framework. The bad news is that Apple is quite restrictive on Bluetooth classic development, but hopefully there is something you can do. I didn't see any equivalent to the Core Bluetooth on first glance.

Upvotes: 0

Related Questions