Can not use keyword await outside an async function

1,240 阅读1分钟

解决方案:

在箭头函数前面加 async

cheackLoginAvailable(callback) {
    NativeModules.RLLoginModel.getCheckEnvAvailable(async result => {
        console.log('网络result------', result)
        if (result) {
            callback({ code: 200, message: 'can use' })
        } else {
            // 弹窗提示
            const { title, content, cancelLabel, confirmLabel } = await this.getCellualrConfig()
            CustomAlert.showAlertNView({
                title,
                content,
                cancelLabel,
                confirmLabel,
                doneCallback: () => { },
                cancleCallback: () => {
                    // Linking.openSettings()
                    if (Global.isIOS) {
                        // Linking.openURL('app-settings:').catch(err => console.log('error', err))
                        Linking.openURL('App-Prefs:MOBILE_DATA_SETTINGS_ID')
                    } else {
                        Linking.openSettings()
                    }
                }
            })
        }
    })
}