首页 > 解决方案 > In Debug Mode, API Request works. Release Mode, returns null

问题描述

I am near complete with my react-native app using the iOS simulator to test it. In the Debug Mode, the api requests successfully work and display on the app. However, in Release Mode, only the login request works.

My current details are the following:

 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

I've done the following:

This login API Request works and returns the token I want:

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;
            }
        }

And this is how my project receives its assignments.

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)
            } 

It comes down to receiving the projects and assignments.

In debug mode, I get the desired output of arrays and expect the same in release mode:

https://imgur.com/a/nkHh5LU

But instead, the output I receive is returned as null and in release mode is this:

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

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

标签: iosreact-nativereact-native-ios

解决方案


这是我在这个问题上的一步一步的旅程。

  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。
    • 确保检查他们的网站

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


推荐阅读