react-native-background-fetch: Error using plugin in managed Expo app
Your Environment
- Plugin version: 4.1.10
- Platform: iOS
- OS version: iOS 16.4
- Device manufacturer / model: iPhone 14
- React Native version (
react-native -v): 0.71.8 - Managed Expo application
Expected Behavior
Should be able to install and use the plugin
Actual Behavior
Getting the following error when installing the plugin:
Steps to Reproduce
- ran
npx expo install react-native-background-fetch ioskey in the Expo config file looks like this:
ios: {
supportsTablet: true,
infoPlist: {
UIBackgroundModes: ["fetch", "processing"],
BGTaskSchedulerPermittedIdentifiers: ["com.transistorsoft.fetch"],
},
usesAppleSignIn: true,
},
- Add this to
App.jsfile (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
- Install package and run a background task
Debug logs
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 15 (6 by maintainers)
Hi,
Unfortunately I don’t have access to the code anymore as it was for an old company. We ended up scrapping it anyways because the native API’s for this were not reliable enough.
Great. Good work.
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)