小编Str*_*eck的帖子

expo.io的BackgroundFetch没有运行定义的任务

我目前正在使用expd sdk-version 32开发适用于iOS的应用程序。我必须定期从我的应用程序调用REST服务。为此,我尝试利用新的BackgroundFetch API。

这是我的代码:

const BACKGROUND_LOCATION_SENDING_TASK = "BACKGROUND_LOCATION_SENDING_TASK";

async function initBackgroundLocationSending() {
    console.log("initBackgroundLocationSending()");

    TaskManager.defineTask(BACKGROUND_LOCATION_SENDING_TASK, () => {

        // this console.log does never get called ... 
        console.log("BACKGROUND_LOCATION_SENDING_TASK");

        // i will implement real fetch logic here when i found out how to get this function called.
        return BackgroundFetch.Result.NewData;
    });

    console.log("is task registered ... ");
    let isRegistered = await TaskManager.isTaskRegisteredAsync(BACKGROUND_LOCATION_SENDING_TASK);
    console.log("isRegistered: ", isRegistered);

    if(isRegistered) {
        console.log("unregister task ...");
        await BackgroundFetch.unregisterTaskAsync(BACKGROUND_LOCATION_SENDING_TASK);
        console.log("Done");
    }

    console.log("is task registered ... ");
    isRegistered = await …
Run Code Online (Sandbox Code Playgroud)

ios background-fetch react-native expo

7
推荐指数
1
解决办法
1029
查看次数

标签 统计

background-fetch ×1

expo ×1

ios ×1

react-native ×1