react-native-background-fetch: Couldn't get it working on iOS

Your Environment

  • Plugin version: 3.1.0
  • Platform: iOS
  • OS version: 14.2
  • Device manufacturer / model: iPhone 11 / iPhone X
  • React Native version (react-native -v): 0.63.3
  • Plugin config

Expected Behavior

Working on iOS

Actual Behavior

Won’t work on iOS. I’m getting below errors when simulate background both for simulator and real device. I followed all guides about iOS config

2020-11-24 22:23:43.683333+0300 APP[10864:2764993] [TSBGAppRefreshSubscriber load]: { “react-native-background-fetch” = “<TSBGAppRefreshSubscriber identifier=react-native-background-fetch, executed=0, enabled=1>”; } 2020-11-24 22:23:54.381081+0300 APP[10864:2764993] [TSBackgroundFetch registerForTaskWithIdentifier: react-native-background-fetch 2020-11-24 22:23:54.381977+0300 APP[10864:2764993] [TSBackgroundFetch registerForTaskWithIdentifier: com.transistorsoft.calculate 2020-11-24 21:58:26.419241+0300 APP[10818:2754463] [connection] nw_read_request_report [C9] Receive failed with error “Software caused connection abort” 2020-11-24 21:58:26.309677+0300 APP[10818:2754463] [connection] nw_flow_add_write_request [C14 10.0.1.20:8081 failed channel-flow (satisfied (Path is satisfied), viable, interface: en0, ipv4, dns)] cannot accept write requests 2020-11-24 21:58:56.309783+0300 APP[10818:2754463] [connection] nw_write_request_report [C14] Send failed with error “Socket is not connected” 2020-11-24 22:03:47.870041+0300 APP[10818:2756675] [connection] nw_write_request_report [C27] Send failed with error “Socket is not connected” 2020-11-24 22:04:08.426483+0300 APP[10818:2756592] Connection 37: unable to determine interface type without an established connection 2020-11-24 22:04:08.426525+0300 APP[10818:2756592] Connection 37: unable to determine fallback status without a connection 2020-11-24 22:04:08.904163+0300 APP[10818:2754376] dnssd_clientstub write_all(23) DEFUNCT 2020-11-24 22:04:08.904189+0300 APP[10818:2754376] dnssd_clientstub deliver_request ERROR: write_all(23, 50 bytes) failed 2020-11-24 22:04:08.904230+0300 APP[10818:2754376] dnssd_clientstub write_all(23) DEFUNCT

Steps to Reproduce

  1. npx react-native run-ios or
  2. Run on real device via xCode and wait for xcode output

Context

I’m trying to basically console.log on app refresh to make sure it’s working at the moment

Code

home.js

// inside componentDidMount()
            BackgroundFetch.configure(
              {
                minimumFetchInterval: 15,
                forceAlarmManager: false, // For Android, accuracy
                stopOnTerminate: false,
                startOnBoot: true,
                requiredNetworkType: BackgroundFetch.NETWORK_TYPE_ANY,
                requiresCharging: false,
                requiresDeviceIdle: false,
                requiresBatteryNotLow: false,
                requiresStorageNotLow: false,
                enableHeadless: true,
              },
              async (taskId) => {
                console.log("Background Task ID: ", taskId);
                console.log("RAN CALCULATE BAR"); // This outputs on android but never on iOS
                BackgroundFetch.finish(taskId);
              },
              (error) => {
                console.log("Background Error: ", error);
              }
            );

index.js

const MyHeadlessTask = async (event) => {
  let taskId = event.taskId;
  console.log("[BackgroundFetch HeadlessTask] start: ", taskId);
  BackgroundFetch.finish(taskId);
};

BackgroundFetch.registerHeadlessTask(MyHeadlessTask);

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 1
  • Comments: 49 (19 by maintainers)

Most upvoted comments

Correct, it will almost never be every 15 minutes.

Reading steps count

I’ve never used the iOS CMPedometer, but I believe you just need to tell that API to start and the OS gathers this data in the background but doesn’t necessarily keep your app alive. There is an API method queryPedometerDataFromDate:toDate:withHandler for retrieving historical data.

While you won’t get real time data, you can gather the data once your app returns to the foreground.

I have the same problem with the same env. Everything is fine when I debugging, task has been registered. https://github.com/transistorsoft/react-native-background-fetch#debugging.

But It doesn’t work on release build I tested on ios 13.7 too and nothing difference

update, it work on ios 13.7, tks !