在调试模式下,API 请求有效。释放模式,returns 空

In Debug Mode, API Request works. Release Mode, returns null

我使用 iOS 模拟器来测试我的 react-native 应用程序已经接近完成。在调试模式下,api 请求成功运行并显示在应用程序上。但是,在发布模式下,只有登录请求有效。

我目前的详细信息如下:

 react-native: 0.60.3,
 native-base: 2.13.5,
 react-native-cli: 2.0.1,

 Visual Studio Code 1.36.1 
 Xcode 11 beta 7

我做了以下事情:

此登录 API 请求有效并且 returns 我想要的令牌:

async(data) => {
            try{
                const url = 'https://assets.breatheco.de/apis/credentials/auth'
                let response1 = await fetch(url, {
                    method: 'POST',
                    body: JSON.stringify(data),
                    headers: {
                        'Authorization':'application/json',
                        'Content-Type':'application/json'
                    }, 
                });
                // console.log(response)
                let res = await response1.json();
                if (response1.status >= 200 && response1.status < 300) {
                    data.error = "";
                    let user = res;
                    console.log('userToken: ', user, typeof(user))
                    getActions().userToken.store(user);
                } else {
                    let error = res;
                    console.log("something went wrong in getting userToken", error, getStore().userToken);
                    return false;
                    throw error;
                }

            } catch(error) {
                {() => getActions().userToken.remove()};
                console.log("Email: ", data.username);
                console.log("Password: ", data.password);
                console.log("Error: ", error);
                throw data.error;
            }
        }

这就是我的项目接收分配的方式。

async() => {
       console.log('entering get Tasktoken')
            try {
                let store = getStore()
                let session = store.userToken;

                let accessToken = session.access_token;
                let student_id = session.id;
                console.log(student_id)

                const taskURL = "https://api.breatheco.de/student/" + student_id + "/task/" 
                console.log('link is '+ taskURL);

                let response2 = await fetch(taskURL, { 
                    method: 'GET',
                    cache: 'no-cache',
                    headers: {
                        'Authorization': 'Bearer ' + accessToken,
                        'Content-Type': 'application/json',
                        'Cache-Control': 'no-cache'},
                    body: JSON.stringify(),

                    });
                let tasks = await response2.json();
                console.log('tasks:',tasks)
                getActions().taskToken.store(tasks);

            } catch(error) {
                console.log('something went wrong in getting taskToken', error)
            } 

归结为接收项目和任务。

在调试模式下,我得到了所需的数组输出,并期望在发布模式下相同:

https://imgur.com/a/nkHh5LU

但是,我收到的输出返回为 null,在发布模式下是这样的:

Error: { [Error: No input to stringify] }

https://imgur.com/a/3Sm1Y9t

这是我解决这个问题的一步一步的旅程。

  1. 恢复出厂设置

    • 我最终不得不恢复出厂设置
    • 还得再次升级到最新的Catalina/Xcode。
  2. 开始新项目

    • 我保存了 src 文件、package.json、应用程序图标和其他细节
    • react-native init AwesomeNativeBase
    • 的新项目构建它
  3. 已更改部署目标

    • 我在文件程序里搜索了所有IOS_DEPLOYMENT_TARGET = {version number here},改成了11.0。
    • pod install
    • 开始
  4. 更新 React 和 React-Native

    • 你拥有最新版本的 React 和 React-Native 是最基本的。
    • 确保检查他们的网站

这不是最干净的解决方案,但它对我有用。