Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

To establish a connection between Ionic BLE and a device's Mac Address on iOS:

  1. Install the Ionic Native BLE plugin in your Ionic project by running the following command in your terminal:

    ionic cordova plugin add cordova-plugin-ble-central
    npm install @ionic-native/ble
    
  2. Import the Ionic Native BLE plugin in your component, and create a function to connect to a device using the device's Mac Address:

    import { BLE } from '@ionic-native/ble/ngx';
    
    export class HomePage {
    
     constructor(private ble: BLE) { }
    
     connectToDevice(macAddress: string) {
       this.ble.connect(macAddress).subscribe(
         peripheral => console.log('Connected to', peripheral),
         error => console.log('Error connecting to', macAddress, error)
       );
     }
    
    }
    
  3. Call the connectToDevice function with the Mac Address of the device you want to connect to:

    this.connectToDevice('00:11:22:33:44:55');
    

Note: Make sure that the device's Bluetooth is turned on and that the device is discoverable. Also, some devices require a pairing process before they can be connected, so make sure to check the device's documentation for any specific instructions.