-
Notifications
You must be signed in to change notification settings - Fork 513
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Issue with [BleError: Operation was cancelled] on iOS 17 #1230
Comments
@HwangJungeon What iOS minor version are you on? |
|
Same here using 3.2.1 on:
Tried several "connect/disconnect" combinations all with the same result: Help appreciated too. Thanks!!! |
@ebadia |
I deleted node_modules folder, install them again, but the error persists. Thanks for your response! |
It still happens to me too... I'll continue to try different things to fix the error, and if I find a good solution, I'll share it! |
Thanks, I will do the same |
Hi @HwangJungeon @ebadia |
This is the code I use to identify and connect to the BLE device (a weight scale)
This is the log from this piece of code:
Hope it helps you! |
I apologize for the delayed response to your comment. As the issue persists, I've attempted the following approach, which seems to work without any problems: if (error instanceof Error && error.message.includes('Operation was cancelled')) {
this.manager.destroy();
this.manager = new BleManager();
return this.connectToDevice(deviceId);
} This method catches the "Operation was cancelled" error, destroys the existing instance, creates a new one, and then attempts to reconnect to the device. Do you think this approach is acceptable to use? |
Still have issues, will continue trying different approaches. Thanks! |
Have you settled on a new approach? Running into the same error. |
@zachTrio The method I showed is simple, but still works well. I'm still using it and it's working fine on iOS 18. |
@HwangJungeon I'll give it a go. Though, I feel like I was trying to still track down where this error was throwing when I commented on this issue. The stack trace was fairly useless from what I remember and I think just about everything can throw the 'Operation was cancelled' What function/s are you catching here. |
Hi, I encountered this error as well, and fixed it. The error comes from iOS scanning very quickly in the To fix this, you can do the following:
bleManager.startDeviceScan(
[SERVICE_UUID_LIST],
{
allowDuplicates: false, // <----- This line
callbackType: ScanCallbackType.AllMatches,
scanMode: ScanMode.LowLatency
},
deviceFoundFunction
)
function startDeviceScanWrapper(deviceName:string){
let currentDeviceId = ""; // Set variable that keeps track of what we are busy with
bleManager.startDeviceScan( [SERVICE_UUID_LIST],
{
allowDuplicates: false,
callbackType: ScanCallbackType.AllMatches,
scanMode: ScanMode.LowLatency
},
async (error, device) => { // <------ Start of device scan callback listener
if (error) {
await logger(`🛑: Error scanning for devices: ${error}`);
return;
}
// Check if we got a device, and if it's the correct one
if (
device &&
device.isConnectable &&
(device.name === deviceName || device.localName === deviceName)
) {
const name = device.name ?? device.localName;
await logger(`✅: Found device: ${name}`);
if (currentDeviceId === device.id) {
await logger(
"🛑: Multiple connection attempts to a single device. Dropping this attempt."
);
return;
} else {
currentDeviceId = device.id;
}
// ..... Rest of your code after this to handle connecting to a device
// Something like device.connect(......)
}
} Hope this helps! |
Prerequisites
Question
Hello,
I am encountering an issue with the [BleError: Operation was cancelled] error on iOS 17. This problem does not occur when testing on AOS, but it started appearing on iOS after a period of smooth operation. The issue persists consistently.
I have reviewed and attempted solutions suggested in previous issues, such as Connection Error 2 "Operation was cancelled" on IOS16 #1080. I tried using
device.cancelConnection()
beforedevice.connect()
and modified my code to ensure thatnew BleManager()
is called only once by implementing a singleton pattern. Despite these efforts, the problem remains unresolved.The most perplexing aspect is that the connection works fine on iOS initially, but the error reappears the next day upon retrying.
Additionally, I have verified iOS permissions, cleaned the iOS build folder, and retried the process. I am currently using the latest version of
react-native-ble-plx
(3.2.1).Environment:
Any assistance or insights into resolving this issue would be greatly appreciated.
Thank you.
Question related code
No response
The text was updated successfully, but these errors were encountered: