Запросы Axios в фоновом режиме выполняются успешно. Я вижу его ответ.
Но функции fetch и firebase зависли.
Я не получаю ошибок. Запрос просто зависает.
Как только приложение выходит на передний план, функция fetch и firebase завершается, и я вижу ответ.
Вот мой код:
Код: Выделить всё
TaskManager.defineTask(BACKGROUND_FETCH_TASK, async () => {
await bgCall();
return BackgroundFetch.BackgroundFetchResult.NewData;
});
const bgCall = async () => {
console.log("Calling endpoints...");
const networkState = await Network.getNetworkStateAsync();
//I can see this response in the console and confirm that network connection exists
console.log(`[ BG ] Current network type: ${JSON.stringify(networkState)}`);
const axiosResp = await axios.get("https://api.ipify.org?format=json");
//I can also see the IP in the console
console.log("[ BG ] axios resp", axiosResp.data);
let response;
//This is where the code is stuck until the app comes to foreground
response = await fetch("https://api.ipify.org?format=json");
console.log("[ BG ] fetch API response", response);
//The code is also stuck here in the background
const fbCall: any = await httpsCallable(firebaseFunctions, "getData")({ ...data });
console.log("[ BG ]",fbCall);
};
Код: Выделить всё
"expo": "^52.0.23",
"expo-background-fetch": "~13.0.3",
Когда я помещаю вызов функции Firebase перед вызовом выборки, наблюдается тот же результат.
Подробнее здесь: https://stackoverflow.com/questions/793 ... roundfetch
Мобильная версия