第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會有你想問的

等待映射內(nèi)的所有異步函數(shù)完成執(zhí)行

等待映射內(nèi)的所有異步函數(shù)完成執(zhí)行

POPMUISE 2022-09-02 16:04:52
我想在映射內(nèi)完成所有異步函數(shù)的執(zhí)行,然后更改組件的狀態(tài)。我給你留了一個(gè)減少的代碼部分,以防你能幫助我。我所要做的就是在每次用戶取消時(shí)顯示我自己的權(quán)限屏幕。為了簡化,我有這個(gè):const permissions = {    cameraRoll: {        iconType: "ionicon",        iconName: "ios-images",        title: "Enable camera roll",        subtitle:          "To upload content from your Gallery, you have to granted the camera roll permission",        buttonText: "Enable camera roll",        checkPermission: checkCameraRollPermission,        requirePermission: requireCameraRollPermission,      },    };}const checkCameraRollPermission = async () => {    const { status, canAskAgain } = await Permissions.getAsync(      Permissions.CAMERA_ROLL    );    return { status, canAskAgain };  };  const requireCameraRollPermission = async () => {    const { status, canAskAgain } = await Permissions.askAsync(      Permissions.CAMERA_ROLL    );    return { status, canAskAgain };  };/* I HAVE TO WAIT FOR ALL THE FUNCTIONS TO FINISH EXECUTIONFOR EACH OBJECT ON THE MAP BUT THIS IS NOT WORKING :( */getMissingPermissions = () => {    // Only check permissions on the foreground    if (AppState.currentState.match(/active/)) {      // We have to empty the current missing permssions and recalculate them      const permissionsArray = [];      Promise.all(        Object.keys(permissions).map((key) => {          permissions[key].checkPermission().then(({ status }) => {            if (status !== "granted") {              permissionsArray.push(permissions[key]);            }          });        })      ).then(() => {        this.setState({          missingPermissions: permissionsArray,        });      });    }  };有什么想法嗎?謝謝
查看完整描述

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,

        });

      });

    }

  };


查看完整回答
反對 回復(fù) 2022-09-02
  • 1 回答
  • 0 關(guān)注
  • 94 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號