React Native(Android)未处理的承诺拒绝-网络请求

时间:2020-11-09 10:12:48

标签: javascript android react-native

我最近创建了一个Expo项目,该项目可以在iOS / Web上正常运行,但是在Android设备上却出现标题中描述的错误。

发生的事情是,该应用程序打开,并在按下按钮时打开了登录屏幕,该屏幕上显示了巫婆的登录屏幕。

POST请求看起来像这样:

_userLogin() {
        let username = this.state.username;
        let password = this.state.password;
      
        fetch("https://domain/login-react", {
          method: "POST",
          headers: {
            'Accept': 'application/json',
            'Content-Type': 'application/json',
            'Accept-Encoding': 'gzip,deflate'
          },
          body: JSON.stringify({
            username: username,
            password: password,
          }),
        })
        .then((response) => response.json())
        .then((responseData) => {
          if(responseData.status == 1) {
              //saving user
            this.setState({isLoggedIn: responseData.status});
            this.setState({detaliiUser: responseData.detaliiUser});
            AsyncStorage.setItem('USER_ID',JSON.stringify(this.state.detaliiUser['Id']));
            
            //redirect to products page
            this.props.navigation.navigate('Liste Utilizator');
          }else{
            this.setState({mesajEroare: responseData.status});
          }
        })
      }

出于隐私原因,我替换了实际的提取网址

在我的app.json中,android权限配置如下:

"android": {
      "permissions" : ["ACCESS_COARSE_LOCATION", "ACCESS_FINE_LOCATION", "CAMERA", "INTERNET"],
      "adaptiveIcon": {
        "foregroundImage": "./assets/adaptive-icon.png",
        "backgroundColor": "#FFFFFF"
      },
      "package": "app.htgps.listare"
    },

我得到的错误:

[Unhandled promise rejection: TypeError: Network request failed]
- node_modules\whatwg-fetch\dist\fetch.umd.js:527:17 in setTimeout$argument_0
- node_modules\react-native\Libraries\Core\Timers\JSTimers.js:130:14 in _callTimer
- node_modules\react-native\Libraries\Core\Timers\JSTimers.js:383:16 in callTimers
- node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:416:4 in __callFunction
- node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:109:6 in __guard$argument_0
- node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:364:10 in __guard
- node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:108:4 in callFunctionReturnFlushedQueue
* [native code]:null in callFunctionReturnFlushedQueue

另一个奇怪的事情是,当我运行expo build:android时,该应用程序不会在我测试运行“ Android 10”的设备上请求任何许可

过去2天,我用Google搜索,并尝试了多种可能的解决方案,但找不到适合我的解决方案。

我可以提供任何帮助,也感谢任何形式的建议。

谢谢,CR

0 个答案:

没有答案