Description
Hi guys,
I'm trying to add this plugin for use on iOS phones but I'm not having any success in implementing it. However, for Android phones, it works perfectly.
Actually, the code is the same for both platforms. Let me explain a little bit what's happening with images and functions in code:
- In our app we have a button where the initialize() is done:
initializeBleClient(): Promise<boolean> {
return new Promise(async (resolve, reject) => {
try {
await BleClient.initialize();
resolve(true);
} catch (error) {
console.error(error);
reject(false);
}
})
}
- Once initialized, it does this function (scan the devices):
scanDevicesByOperatorUUID(): Promise<BleDevice> {
return new Promise(async (resolve, reject) => {
try {
const selectedDevice = await BleClient.requestDevice(
{
services: [this._serviceUUID]
}
);
console.log("Selected device: ", selectedDevice);
this.setSelectedDevice(selectedDevice);
resolve(selectedDevice);
} catch (error) {
reject(undefined)
}
});
}
- We select the device shown in the list:
connectToPickio(): Promise<boolean> {
return new Promise(async (resolve) => {
try {
if (this.getSelectedDevice()) {
await BleClient.disconnect(this.getSelectedDevice()!.deviceId);
BleClient.connect(this.getSelectedDevice()!.deviceId, () => this.disconnectActions()).then(() => {
this.trackDeviceRSSI();
this.signalModalShowing = 0;
resolve(true);
}).catch(() => resolve(false));
} else {
resolve(false);
}
} catch (error) {
resolve(false);
}
});
}
- It is connecting at the operating system level and not the application level, making it impossible for us to connect and move forward:
And then, we have some logs that we saw in the Xcode App:
⚡️ To Native -> BluetoothLe removeListener 51121821
⚡️ To Native -> BluetoothLe addListener 51121822
⚡️ To Native -> BluetoothLe connect 51121823
⚡️ BluetoothLe - Connecting to peripheral <CBPeripheral: 0x3018109c0, identifier = 338676A7-6DF4-02F6-210B-A84762F07FA6, name = pickio-004-005, mtu = 517, state = connected>
⚡️ [error] - ERROR {"errorMessage":"Connection timeout"}
⚡️ BluetoothLe - Connected to device <CBPeripheral: 0x3018109c0, identifier = 338676A7-6DF4-02F6-210B-A84762F07FA6, name = pickio-004-005, mtu = 517, state = connected>
⚡️ BluetoothLe - Resolve connect|338676A7-6DF4-02F6-210B-A84762F07FA6 Successfully connected.
⚡️ BluetoothLe - Connected to peripheral. Waiting for service discovery.
⚡️ BluetoothLe - Reject connect Connection timeout
ERROR MESSAGE: {"message":"Connection timeout","errorMessage":"Connection timeout"}
⚡️ [error] - {"message":"Connection timeout","errorMessage":"Connection timeout"}
iOS Version: 18.1
Angular: 18.0.0
Ionic: 8.0.0
Capacitor Community BLE: 6.0.0
Thank you very much, guys!! :D