question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Scanning in background task.

See original GitHub issue

Prerequisites

  • I am running the latest version
  • I checked the documentation and found no answer
  • I checked to make sure that this issue has not already been filed

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:

const my_service  = 'c7fcee6f-e7e0-8c8a-b745-fde27c268efd';
manager.startDeviceScan([my_service], {allowDuplicates: true}, (error, device) => {
            if (error) {
                console.log("Error in device scan: ", JSON.stringify(error));
            }

            if (device) {
                 console.log("DEVICE UUIDS: ", device.serviceUUIDs);
            }
        });

In the console this log is printed:

'DEVICE UUIDS: ', [ '00001805-0000-1000-8000-00805f9b34fb',
  'c7fcee6f-e7e0-8c8a-b745-fde27c268efd' ]

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.

manager.startDeviceScan(['00001805-0000-1000-8000-00805f9b34fb', 'c7fcee6f-e7e0-8c8a-b745-fde27c268efd'], {allowDuplicates: true}, (error, device) => {
        console.log("Anything?");
        if (error) {
            console.log("Error in background device scan: ", JSON.stringify(error));
        }

        if (device) {
            console.log("DEVICE UUIDS: ", device.serviceUUIDs);
            console.log("Found device in background scan: ", device.id);
        }
    });

I am setting log level to verbose. This is the only relevant log I have found:

'CentralManager(10766645056) scanForPeripherals(
withServices: Optional("[00001805-0000-1000-8000-00805F9B34FB, C7FCEE6F-E7E0-8C8A-B745-FDE27C268EFD]"),
options: Optional(["kCBScanOptionAllowDuplicates": true]))'

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.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:14 (4 by maintainers)

github_iconTop GitHub Comments

6reactions
ezranbayantemurcommented, Mar 12, 2020

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).

Hi, thanks for your efforts! Is background mode supported by Android too?

4reactions
Cierpliwycommented, Feb 21, 2020

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).

Read more comments on GitHub >

github_iconTop Results From Across the Web

Running an On-Demand Scan task in the background
Running an On-Demand Scan task in the background · Open the Properties: On-Demand Scan window. · Select or clear the. Perform task in...
Read more >
Background tasks - SonarQube Documentation
A background task can be: the import of an analysis report, the computation of a portfolio, ... What happens after the scanner is...
Read more >
dotintent/react-native-ble-plx - Scanning in background task.
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...
Read more >
Using Background Tasks | Apple Developer Documentation
Background scanning shares a budget with the timely alert tasks, so your app can only perform a few background scans per day.
Read more >
Background BLE scan in DOZE mode on Android devices
Background BLE scans for Android devices could be divided into two different groups depending on the mechanisms used for scheduling background tasks.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found