我目前正在使用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)