transistorsoft / react-native-background-fetch

Periodic callbacks in the background for both IOS and Android
MIT License
1.43k stars 191 forks source link

How register headless task in expo SDK 50 #493

Open vvusts opened 3 weeks ago

vvusts commented 3 weeks ago

Your Environment

Expected Behavior

Use this plugin with expo project with headless mode on.

Actual Behavior

Missing documentation on how to use headless mode in expo.

This is question, as plugin works perfectly with react native CLI (tested on most androids) even when app is terminated. Expo SDK50 doesn't have index.js file, so I don't know where to put this code:

AppRegistry.registerComponent(appName, () => App);

const backgroundFetchHeadlessTask = async (event) => {
  await Event.create...
  BackgroundFetch.finish(event.taskId);
}

/// Now register the handler.
BackgroundFetch.registerHeadlessTask(backgroundFetchHeadlessTask);

Since in expo project there is no AppRegistry.registerComponent. It could be good idea to see somewhere in documentation how to integrate plugin in expo. I mean it is easy to install it but adding this code for index file is missing.

christocracy commented 3 weeks ago

📂 package.json:

{
+  "main": "index.js"
}
import registerRootComponent from 'expo/build/launch/registerRootComponent';

import App from './App';

registerRootComponent(App);

// Add your HeadlessTask here
//
//
vladimir-vucetic commented 3 weeks ago

I’ll give it a try. I didn’t have idea it could be done like this in expo.