【问题标题】:Cant api connection doesnt work on production react nativeapi连接能否在生产反应本机上不起作用
【发布时间】:2020-03-14 16:34:30
【问题描述】:

在将 react 本机应用程序构建到生产环境之前,我能够登录并且可以收到任何错误的错误消息,但是在构建到 apk 之后,我在我的 Android 手机上运行了该应用程序,但它没有工作。

我正在获取这样的用户登录信息;

import { userTypes } from '../../types';
const { USER_LOGIN } = userTypes;

const SERVER_URL = "http://localhost:8080/api/v1";

const loginAction = (userdata) => dispatch => {
    fetch(`${SERVER_URL}/auth/signin`,{
        method: 'POST',
        headers: {
            'content-type' : 'application/json',
        },
        body: JSON.stringify(userdata)
    })
    .then(res => res.json())
    .then(data =>(
        dispatch({
        type: USER_LOGIN,
        payload: data
    })))
}

export {
    loginAction
};

是否有在开发和生产中使用 api 连接的正确方法。

【问题讨论】:

  • 您是否授予apk 使用互联网的权限?
  • @ApplePearPerson 你的意思是这个<uses-permission android:name="android.permission.INTERNET" />我已经有了

标签: reactjs api react-native express redux


【解决方案1】:

我猜你使用的是 android 9。如果是这种情况,试试这个:

添加您的主 AndroidManifest.xml

<manifest xmlns:tools="http://schemas.android.com/tools"> 
    <application android:usesCleartextTraffic="true" tools:targetApi="28">                                         </application>  
</manifest>

【讨论】:

    猜你喜欢
    • 2019-07-08
    • 2016-08-01
    • 2020-05-03
    • 2021-08-23
    • 1970-01-01
    • 1970-01-01
    • 2018-08-31
    • 2019-05-02
    • 1970-01-01
    相关资源
    最近更新 更多