1 回答

TA貢獻(xiàn)1789條經(jīng)驗(yàn) 獲得超10個(gè)贊
您需要以數(shù)組的形式提供承諾。目前,您沒有從地圖中返回任何內(nèi)容,這是導(dǎo)致問題的原因。Promise.all
此外,代替使用 permissionsArray 變量,您可以簡單地從嵌套 promise 中返回所需的值,該值將在響應(yīng)中可用Promise.all(...).then(...)
getMissingPermissions = () => {
// Only check permissions on the foreground
if (AppState.currentState.match(/active/)) {
// We have to empty the current missing permssions and recalculate them
Promise.all(
Object.keys(permissions).map((key) => {
return permissions[key].checkPermission().then(({ status }) => {
if (status !== "granted") {
return permissions[key];
}
return;
});
})
).then((res) => {
const permissionsArray = res.filter(Boolean)// Filter out undefined values
this.setState({
missingPermissions: permissionsArray,
});
});
}
};
添加回答
舉報(bào)