我正在使用WorkManager进行后台服务。我的代码如下:
有没有办法在executeTask中等待异步方法?
void callbackDispatcher() {
Workmanager.executeTask((task, inputData) async {
switch (task) {
case "uploadLocalData":
print("this method was called from background!");
await BackgroundProcessHandler().uploadLocalData();
print("background Executed!");
return true;
break;
case Workmanager.iOSBackgroundTask:
print("iOS background fetch delegate ran");
return true;
break;
}
return false;
});
}
有没有办法在executeTask中等待异步方法?
uploadCompleter.complete();
上面添加了await uploadCompleter.future;
,这对我来说完美地解决了问题。谢谢 @GazihanAlankus - undefineduploadCompleter.complete();
之前等待uploadCompleter.future;
,它永远不会执行到uploadCompleter.complete();
,对吗? - undefined