Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

229
Visualizações
Expo background fetch initialize but never running

While developping my react native app, I need to do a periodic background fetch to another server. So I import 2 class from expo :

import * as BackgroundFetch from 'expo-background-fetch';
import * as TaskManager from 'expo-task-manager';

and initialize my background task :

const fetchFunc = async () => {
    try{
        console.log("Hi from fetch function !")
        return BackgroundFetch.BackgroundFetchResult.NoData;
    }
    catch(err)
    {
        return BackgroundFetch.BackgroundFetchResult.Failed;
    }
}

Register this task :

async function registerBackgroundFetchAsync() {
    try{
        await BackgroundFetch.registerTaskAsync("func-fetch", {
            minimumInterval: 5, // 5 second
        })
        console.log("background fetch enabled")
    }
    catch(err){
        console.error(err);
    }
}

and create a function to execute all of them :

async function initBackgroundFetch() {
    if(!TaskManager.isTaskDefined("func-fetch")){
        TaskManager.defineTask("func-fetch", fetchFunc)
    }

    await registerBackgroundFetchAsync();
}

Now, I try to launch it when my component is mounted (I use class and typescript) :

class MainPage extends Component
{
    componentDidMount() {
        initBackgroundFetch();
    }
    .
    .
    .

}

But in my console output I just got the "background fetch enabled" from the registration... I think that my initBackgroundFetch is in the wrong place, but can't find where I need to put it.

PS : my expo diagnostics

Expo CLI 5.0.3 environment info:
System:
  OS: Linux 5.15 Kali GNU/Linux Rolling 2021.4
  Shell: 5.8 - /usr/bin/zsh
Binaries:
  Node: 14.16.1 - ~/.nvm/versions/node/v14.16.1/bin/node
  npm: 8.1.0 - ~/.nvm/versions/node/v14.16.1/bin/npm
npmPackages:
  expo: ^43.0.3 => 43.0.3 
  react: 17.0.1 => 17.0.1 
  react-dom: 17.0.1 => 17.0.1 
  react-native: 0.64.3 => 0.64.3 
  react-native-web: 0.17.1 => 0.17.1 
npmGlobalPackages:
  expo-cli: 5.0.3
Expo Workflow: managed
about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda