问题描述
我需要迭代对象的WinRT类型,以注销成功注册的UWP后台任务。
我有权访问该对象
javascript中的BackgroundTaskRegistration.AllTasks,但是我收到了IMapView
注意:该解决方案是使用Cordova设置的,但我是从VS2017手动连接WinRT的。
任何想法都值得赞赏!
解决方法
我尝试做同样的事情并找到了解决方案。这是示例。
const background = Windows.ApplicationModel.Background;
const allTasks = background.BackgroundTaskRegistration.allTasks;
if (allTasks.size > 0) {
let item = allTasks.first();
// item.hasCurrent should be false if the item is empty.
while (item.hasCurrent) {
const current = item.current;
const task = current.value;
// Do something with current task like
if (task.name === 'name') {
}
// move to next
item.moveNext();
}
}
希望这能奏效。