jamesisaac / react-native-background-task

Periodic background tasks for React Native apps, cross-platform (iOS and Android), which run even when the app is closed.
MIT License
1.1k stars 110 forks source link

BackgroundJob.schedule got 8 arguments, expected 11 #2

Closed timrijckaert closed 7 years ago

timrijckaert commented 7 years ago

Trying to run your example code.

import BackgroundTask from 'react-native-background-task'

BackgroundTask.register(() => {
    console.log('Hello from a background task');
    BackgroundTask.finish()
});

screenshot_20170605-155815

register: function(task, {
    period = 9000, // 15 minutes
    timeout = 30,
  } = {}) {
    // Cancel any existing tasks, as we can only have one to match iOS, and we
    // have no way to tell whether the function has changed or not.
    RNBackgroundJob.cancelAll()

    // Register the headless task
    const fn = async () => { task() }
    AppRegistry.registerHeadlessTask(JOB_KEY, () => fn)

    // Schedule it to run as a periodic task
    AppState.getCurrentAppState(
      ({ appState }) => {
        RNBackgroundJob.schedule(
          JOB_KEY,
          timeout,
          period,
          true, // persist after restart
          appState === 'active',
          RNBackgroundJob.ANY, // network type
          false, // requires charging
          false, // requires device idle
        )
      },
      () => { console.error(`Can't get AppState`) }
    )
  },

Error seems to be correct. You are only giving 8 params.

jamesisaac commented 7 years ago

Thanks for reporting. The API has changed in react-native-background-job (the native Android library currently used) v1.1.3. This was initially written against v1.1.0.

If you install v1.1.2 or lower of that library, I think you'll avoid this error.

Or you can make the same changes this user has: https://github.com/HealthReady/react-native-background-task/commit/e302b796ec4193662ab23bfb19f71864e6d25433

As the readme points out, this project is basically just a proof of concept at this point. I would only recommend using it as a starting point for your own implementation. It is something I will be needing for my RN projects, but haven't yet got round to properly implementing or integrating. Hopefully I will be able to devote proper attention to this during the next few weeks and make a real release.

jamesisaac commented 7 years ago

@timrijckaert Native implementation should be ready soon: #5 which removes the 3rd party dependency.