ios - 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:
- Added domains to Permissions in info.plist
- Used different API servers to see if the server I was using was causing the problem
- Tried different optimizations with Debug and Release Mode in Xcode
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:
But instead, the output I receive is returned as null and in release mode is this:
Error: { [Error: No input to stringify] }
解决方案
这是我在这个问题上的一步一步的旅程。
恢复出厂设置
- 我最终不得不恢复出厂设置
- 还不得不再次升级到最新的 Catalina/Xcode。
刚开始的项目
- 我保存了 src 文件、package.json、应用程序图标和其他细节
- 用一个新项目构建它
react-native init AwesomeNativeBase
更改的部署目标
- 我
IOS_DEPLOYMENT_TARGET = {version number here}
在文件程序中搜索了所有内容并将其更改为11.0。 - 用一个
pod install
- 我
更新 React 和 React-Native
- 它的基础是你拥有最新版本的 React 和 React-Native。
- 确保检查他们的网站
它不是最干净的解决方案,但它对我有用。
推荐阅读
- reactjs - React.js 中的 AFC 中继器和 wp-rest api
- python - 如何移动粒子
- java - 链接列表的“设置”方法的实现?
- javascript - How to write a function to filter an array in javascript?
- python - 单击硒中的按钮
- css - 大网格css没有图片显示
- java - 为什么将“0000:00:00 00:00:00”解析为日期返回-0001-11-28T00:00:00Z?
- jquery - 如何使用来自 API 的 JSON 填充选择列表?
- swiftui - 从 ActionSheet 删除时 ForEach 不更新
- android - 如何设置在 BottomAppBar 隐藏/显示时触发的侦听器?