transistorsoft / react-native-background-fetch

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

Error using plugin in managed Expo app #456

Closed azizsaad closed 10 months ago

azizsaad commented 10 months ago

Your Environment

Expected Behavior

Should be able to install and use the plugin

Actual Behavior

Getting the following error when installing the plugin:

Screenshot 2023-07-17 at 15 14 52

Steps to Reproduce

  1. ran npx expo install react-native-background-fetch
  2. ios key in the Expo config file looks like this:
 ios: {
      supportsTablet: true,
      infoPlist: {
        UIBackgroundModes: ["fetch", "processing"],
        BGTaskSchedulerPermittedIdentifiers: ["com.transistorsoft.fetch"],
      },
      usesAppleSignIn: true,
    },
  1. Add this to App.js file (entry point to project)

import App from "./app/app.tsx"
import BackgroundFetch from "react-native-background-fetch"

SplashScreen.preventAutoHideAsync()

function IgniteApp() {
  return <App hideSplashScreen={SplashScreen.hideAsync} />
}

registerRootComponent(IgniteApp)
bgWorker()

const addEvent = (taskId) => {
  // Simulate a possibly long-running asynchronous task with a Promise.
  return new Promise((resolve, reject) => {
    console.log(taskId)
    resolve(true)
  })
}

const initBackgroundFetch = async () => {

  const onEvent = async (taskId) => {
    console.log("[BackgroundFetch] task: ", taskId)

    await addEvent(taskId)

    BackgroundFetch.finish(taskId)
  }

  const onTimeout = async (taskId) => {
    console.warn("[BackgroundFetch] TIMEOUT task: ", taskId)
    BackgroundFetch.finish(taskId)
  }

  const status = await BackgroundFetch.configure({ minimumFetchInterval: 15 }, onEvent, onTimeout)

  console.log("[BackgroundFetch] configure status: ", status)
}

export const bgWorker = () => {
  console.log("bgWorker")
  return initBackgroundFetch()
}

export default IgniteApp

Context

Debug logs

azizsaad commented 10 months ago

cc @christocracy Added the new issue here - thanks!

christocracy commented 10 months ago

https://github.com/transistorsoft/react-native-background-fetch/blob/master/docs/INSTALL-EXPO.md#open_file_folder-appjson

You need to add "plugins" to your app.json

azizsaad commented 10 months ago

https://github.com/transistorsoft/react-native-background-fetch/blob/master/docs/INSTALL-EXPO.md#open_file_folder-appjson

You need to add "plugins" to your app.json

Sorry for not clarifying this in the original issue, but I believe I have:

 plugins: [
      "react-native-background-fetch", // background worker
      [
        "expo-image-picker", // image picker
        {
          photosPermission: "Allow access your photos",
        },
      ],
    ],
christocracy commented 10 months ago

And what about the final section in the Setup doc: Re-build?

azizsaad commented 10 months ago

And what about the final section in the Setup doc: Re-build?

Does that not only apply to Android apps? as stated: "You must rebuild your Android app for the added plugins to be evaluated."

Side-question - this is akin to ejecting from a managed to bare workflow, is it not?

christocracy commented 10 months ago

I believe the word "Android" should be omitted.

Run it.

azizsaad commented 10 months ago

I believe the word "Android" should be omitted.

Run it.

I have - the ios and android directories have been created, but the error is still appearing

christocracy commented 10 months ago

I don't know

azizsaad commented 10 months ago

I am running this in the Expo Go app - should that make a difference with this error?

christocracy commented 10 months ago

I don't know. I have little experience with Expo Go and I'm too swamped with other stuff to look into it.

azizsaad commented 10 months ago

No worries - thank you anyways!!

azizsaad commented 10 months ago

Hey, I realised my issue.

I was testing this on the Expo Go app, which would not work as, if I understand correctly, the Expo Go app is only compatible with the Expo SDK packages.

I had to create a custom Development Client build with the EAS CLI, create this build on their infrastructure, scan the QR code and open the dev-client app on my physical phone (background-fetch doesn't work on iOS Simulator it seems)

christocracy commented 10 months ago

Great. Good work.