Connecting a Bluetooth Card Reader

Note that this sample includes code for handling when multiple bluetooth devices are found - here, the solution is the simple use the first in the list while production code would present a user interface to select the proper device.

// To connect via bluetooth, simply pass the BluetoothCardReaderConnectionListener parameter.
CardReader.connect(new BluetoothCardReaderConnectionListener() {

    @Override
    public void onCardReaderConnected(CardReader cardReader) {
        // The connected card reader will be returned in this method.  You can now use it.
        // Card reader connected, name = cardReader.getModelDisplayName()
    }

    @Override
    public void onCardReaderConnectionFailed(MeaningfulError meaningfulError) {
        // Something went wrong.  Check the error
        // meaningfulError.toString() contains error text;
    }

    @Override
    public void onMultipleBluetoothDevicesFound(List<BluetoothDevice> matchingDevices) {

        // In the unlikely event that there are more than one bluetooth devices in range,
        // this callback will get fired.  You will need to select one of the devices and connect to it.

        // Should prompt the user to select one device to connect out of the matchingDevices candidate list.

        // For this example, we'll just take the first one in the list for simplicity and connect to it.
        BluetoothDevice device = matchingDevices.get(0);

        CardReader.connect(device, listener);
    }
    
});
- (IBAction)connectBluetooth:(id)sender {
    [[ANPCardReaderController sharedController] connectBluetoothReader:^(NSArray<ANPBluetoothDevice *> * _Nullable readers) {
        NSLog(@"Found BT devices --> %@", readers);
    }];
}