react-native-background-fetch: react-native-background-fetch not working [ios] and Simulate Background Fetch is disabled in xcode

Your Environment

  • Plugin version: ^3.0.5
  • Platform: iOS
  • OS version: 13.5
  • Device manufacturer / model: XR, 11 pro, 8 plus, Ipad pro 11 inch
  • React Native version (react-native -v): ^0.62.1
  • Plugin config:

try {

  BackgroundFetch.configure(

    {
      minimumFetchInterval: 240,
      requiredNetworkType: BackgroundFetch.NETWORK_TYPE_ANY
    },

    async taskId => {

      let currentDate = new Date();

      let lastSync =
        currentDate.toLocaleDateString() +
        '@' + currentDate.toTimeString().slice(0, 8);

      storeDataLocally('bgTask', { lastSync: lastSync });

      Sentry.captureMessage(
        `[BackgroundFetch] executed successfully: ${lastSync}`
      );
      BackgroundFetch.finish(taskId);
    }
  );
} catch (err) {
  Sentry.captureException(err);
}

Expected Behavior

It should write the current timestamp of its execution to local storage and log it in Sentry in every 4 hours interval. And if it works successfully, Api call will be added in the execution block.

Actual Behavior

It logged only six times in sentry for for around 10 users in last 11 days.

Steps to Reproduce

I’m calling the background fetch in useEffect() in a context api.

useEffect(() => { init(); });

Context

I am trying to call an API in background and store it in realm database (or local storage in JSON format) and the last sync timestamp is also stored in local storage to show it to user. Right now i’m only testing with timestamp. If it works well i will add the api call.

Debug logs

  • iOS: 2020-06-16 12:21:46.575326+0530 smartAgro[4863:48523] [TSBackgroundFetch load]: ( ) 2020-06-16 12:21:46.575529+0530 smartAgro[4863:48523] [TSBGAppRefreshSubscriber load]: { } 2020-06-16 02:22:33.778897-0700 smartAgro[2350:837051] [TSBackgroundFetch onAppTerminate]

About this issue

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

Most upvoted comments

hi, i have the same issue in the native app with swift. is it a bug in iOS 13? or how can i fix it?

There is a lot of documentation about “how to wake up an iOS app” or “how to start an iOS app that’s terminated etc” on the internet. It’s really something you have to go to school on, so you can learn the real possibilities of the platform and it’s limitations.

As far as I know, if your app is not loved / used by the users, fetch is a dead-end as iOS won’t run your fetch any more. After that you have either motion detection / significant locations / GPS (used by the companion geolocation package here, but Apple will reject you unless you really need use it to improve the user’s life!), or cloud messaging, Sending cloud messages in a way that they will actually wake up the app comes with it’s own set of possibilities and limitations which (as far as I can tell) about 1% of the developer population actually understands.

It’s just not easy, and maybe not even possible, and that’s the iOS platform.

the app needs to be minimized not terminated?

That is correct. Once you terminate the app, there are no more fetch events and certainly no ability to Simulate Background Fetch.