【问题标题】:React-Native Async function Failed in IOS SimulatorIOS模拟器中的React-Native异步功能失败
【发布时间】:2021-12-25 11:23:29
【问题描述】:

我有以下简单的代码,在 Android 中可以正常工作,但在 IOS 中 await 不起作用。

const CheckAsyncfucntion = async () => {
console.log('Before Await execution');
const authenticateuser = await newUser(registration_id); // return true or false
console.log('After Await Execution => ', authenticateuser);
}

在 andorid 中它工作正常。但在 ios 中,两个日志都以未定义的身份验证用户值打印。然后 newUser 值得到回报。

我们将不胜感激。 我正在使用 IOS 模拟器 iphone12 iOS 15.0

【问题讨论】:

    标签: ios react-native async-await ios-simulator


    【解决方案1】:

    我猜问题出在函数newUser

    我的 iOS 模拟器适用于任何如下异步函数。

      const CheckAsyncfucntion = async () => {
        console.log('Before Await execution');
        // return true or false from Promise
        const authenticateuser = await new Promise((resolve, reject) => {
          setTimeout(() => {
            resolve(true);
          }, 2000);
        });
        console.log('After Await Execution => ', authenticateuser);
      };
    
    CheckAsyncfucntion();

    【讨论】:

    • New User函数是一个Axios Instance导出默认函数,它调用Rest API并检查用户是否为新用户。
    猜你喜欢
    • 2019-11-29
    • 1970-01-01
    • 2022-10-21
    • 2016-11-08
    • 2021-08-17
    • 1970-01-01
    • 2017-09-09
    • 2022-11-26
    • 2019-05-27
    相关资源
    最近更新 更多