-
Notifications
You must be signed in to change notification settings - Fork 517
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
Scanning in background task. #529
Comments
Also having this problem on iOS, but on Android it is working well. |
I am still interested in understanding more about how to properly use this library with background modes. There are two relevant pieces of information in the documentation:
A couple of questions I have regarding that:
An example of the proper way to implement background tasks with BLE would probably be very useful for a lot of users, but of course that takes more time to do as all things do. Thanks again for a great library! |
In upcoming days I will research this topic. The result will be a wiki page with all the details. |
I have the same issue.I don't understand how can i use this library in background mode on Ios and Android. |
The restoreStateFunction is fired for you ? If yes, can you explain? |
@AzRunRCE I have no idea what the restoreStateFunction does or how to use it. I have had some luck with the restoreStateIdentifier. By using it, I have been able to use the methods manager.devices([id]) to see what devices are connected to the system but not the app, and the method manager.connectedDevices([uuid]). The first has really only been useful when hot reloading causes stuff the break w/ the ble, but that happens frequently for use during development. The second returned something one time, but I have never seen it do anything since then. |
Specifying both Additionally:
|
Thank you @Cierpliwy, is this along the lines of how you would implement and use restore state identifier and function?
|
Please check documentatation when in doubt: https://polidea.github.io/react-native-ble-plx/#blemanageroptionsrestorestatefunction. |
Hello! I added a new entry in the Wiki with an example application to show you all available possibilities around background mode on iOS. Checkout page here: https://github.com/Polidea/react-native-ble-plx/wiki/Background-mode-(iOS). |
@Cierpliwy This is incredibly thorough. Thank you for your help, it is much appreciated! |
Hi, thanks for your efforts! |
Hi all, any news about Android? thanks |
For anyone interested with Android side: But like iOS; you must provide a UUID for scanning function of manager. This means you can't scan everything on background mode. Basically: const task = async () => {
await new Promise(async () => {
manager.startDeviceScan(
[UUID], // UUID of your devices
{scanMode: ScanMode.LowPower}, // I haven't checked yet but LowLatency mode probably
// drains so much battery, so maybe OS kill our background service.
// So better not to be so aggressive
listener // Do whatever you want when the device has found
)
});
};
await BackgroundService.start(task, options); Speaking of it; You can check your task does scanning, made connections and did some operation with PLUS: You can check if your task running or not with Hope it helps! |
Thanks brother, it works! |
I am looking for a Bluetooth expert consultant (must be US based) to help with Android app background functionality. We have an iOS app that works fairly well, but Android having trouble scanning and reconnecting in the background. Anyone know someone that can help? Experience in React-Native and Bluetooth, especially the react-native-ble-plx library desired. |
Why this doesnt work for me? When in foreground he can find devices, but in background he only "starts" the scanner ("entrei", but never really starts the scanner so I can find a new devices... Really apreciate any help! |
Prerequisites
Expected Behavior
I am using react-native-background-fetch to execute a task when the app is in the background. In that task, I should be able to scan for devices.
Current Behavior
I am able to connect, speak with devices, and do anything except for scan for peripherals in the background task I configured. After searching through these issues, I found a related issue here. To confirm that I have all the correct advertised services, in the foreground process I do this:
In the console this log is printed:
Then in the background task, I perform the scanning process with those exact uuids, but without finding any devices this time.
NOTE: the service '00001805...' is the bluetooth current time service. The service id is really just '1805' or '0x1805' but i'm unsure whats the proper way to scan for a service with an assigned number by the bluetooth sig group.
I am setting log level to verbose. This is the only relevant log I have found:
Library version: 1.0.3
Platform: IOS and Android
I have tried my best to do my due diligence before submitting a bug report. Please let me know what other relevant information I can provide, or what I am missing.
Thank you for your help and excellent library!
As a sidenote, I am pretty unclear on what happens when the app is registered for background modes, and a device or service is reconnected. For instance, in IOS it is recommended to just call connectToDevice(id) when a device disconnects if we want to reconnect. But, lets say, the app performs a data transfer when a component is mounted. If the app is in the background then that component is not mounted and that data transfer is not performed? Because of this confusion is why I am using react-native-background-fetch so I know exactly the code the runs in the background.
The text was updated successfully, but these errors were encountered: