Bluetooth Classic Serial Port
This plugin is written using the iOS Accessory Framework (MFi) to support Classic Bluetooth on iOS.
https://github.com/MaximBelov/cordova-plugin-bluetooth-classic-serial-port
Stuck on a Cordova issue?
If you're building a serious project, you can't afford to spend hours troubleshooting. Ionic’s experts offer premium advisory services for both community plugins and premier plugins.
Installation#
- Capacitor
- Cordova
- Enterprise
$ npm install cordova-plugin-bluetooth-classic-serial-port $ npm install @ionic-native/bluetooth-classic-serial-port $ ionic cap sync
$ ionic cordova plugin add cordova-plugin-bluetooth-classic-serial-port $ npm install @ionic-native/bluetooth-classic-serial-port
Ionic Enterprise comes with fully supported and maintained plugins from the Ionic Team. Learn More or if you're interested in an enterprise version of this plugin Contact Us
#
Supported Platforms- Android
- iOS
- Browser
#
Usage#
ReactLearn more about using Ionic Native components in React
#
Angularimport { BluetoothClassicSerialPort } from '@ionic-native/bluetooth-classic-serial-port/ngx';
constructor(private bluetoothClassicSerialPort: BluetoothClassicSerialPort) { }
// Write a stringthis.bluetoothClassicSerialPort.write("00001101-0000-1000-8000-00805F9B34FB", "hello, world", success, failure);
// Array of int or bytesthis.bluetoothClassicSerialPort.write("00001101-0000-1000-8000-00805F9B34FB", [186, 220, 222], success, failure);
// Typed Arrayvar data = new Uint8Array(4);data[0] = 0x41;data[1] = 0x42;data[2] = 0x43;data[3] = 0x44;this.bluetoothClassicSerialPort.write(interfaceId, data, success, failure);
// Array Bufferthis.bluetoothClassicSerialPort.write(interfaceId, data.buffer, success, failure);
// iOS select accessory
async selectAccessory() { const deviceDiscovery = this.bluetoothClassicSerialPort.setDeviceDiscoveredListener().subscribe(async (connectionConfig) => { deviceDiscovery.unsubscribe(); })
await this.bluetoothClassicSerialPort.discoverUnpaired().catch(error => { deviceDiscovery.unsubscribe(); })
}