我的React-native应用程序已经接近完成,使用iOS模拟器对其进行了测试。在“调试模式”下,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请求有效并返回我想要的令牌:
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)
}
这取决于接收项目和任务。
在调试模式下,我获得了所需的数组输出,并期望在发布模式下也是如此:
但是,相反,我收到的输出作为null返回,并且在发布模式下是这样的:
Error: { [Error: No input to stringify] }
答案 0 :(得分:0)
恢复出厂设置
启动新项目
react-native init AwesomeNativeBase
的新项目来构建它更改的部署目标
IOS_DEPLOYMENT_TARGET = {version number here}
,并将其更改为11.0。 pod install
踢了它更新React和React-Native
这不是最干净的解决方案,但对我有用。