提问人:Joshua Wheeler 提问时间:11/10/2023 更新时间:11/10/2023 访问量:26
我一直在制作一个 React Native 应用程序,它在 Expo Go 中运行良好,没有错误,但在原生 iOS 中崩溃
I have been making a React Native app, it works fine with no errors in Expo Go but it crashes in native iOS
问:
该应用程序在 Expo Go 中运行良好,但是当我在 iOS 上构建模拟器并将其旁加载到设备上时,它会在启动屏幕上崩溃。
App.js:
import React, { useState } from 'react';
import { View, Text, TextInput, Button, ScrollView, StyleSheet } from 'react-native';
export default function App() {
const [ip, setIp] = useState('');
const [serial, setSerial] = useState('');
const [ipInput, setIpInput] = useState('');
const [serialInput, setSerialInput] = useState('');
const fetchRequest = async (url) => {
try {
const response = await fetch(url);
console.log('Request sent:', response);
} catch (error) {
console.error('Error:', error);
}
};
const sleep = (milliseconds) => {
return new Promise(resolve => setTimeout(resolve, milliseconds));
};
const avec = async () => {
if (ip && serial) {
fetchRequest(`http://${ip}/api-sdk/assume_behavior_control?serial=${serial}`);
await sleep(1000);
} else {
console.error('IP or serial is missing.');
}
};
const rvec = async () => {
if (ip && serial) {
fetchRequest(`http://${ip}/api-sdk/release_behavior_control?serial=${serial}`);
await sleep(1000);
} else {
console.error('IP or serial is missing.');
}
};
const fw = async () => {
if (ip && serial) {
fetchRequest(`http://${ip}/api-sdk/move_wheels?lw=140&rw=140&serial=${serial}`);
} else {
console.error('IP or serial is missing.');
}
};
const left = async () => {
if (ip && serial) {
fetchRequest(`http://${ip}/api-sdk/move_wheels?lw=-150&rw=150&serial=${serial}`);
} else {
console.error('IP or serial is missing.');
}
};
const bc = async () => {
if (ip && serial) {
fetchRequest(`http://${ip}/api-sdk/move_wheels?lw=-150&rw=-150&serial=${serial}`);
} else {
console.error('IP or serial is missing.');
}
};
const stop = async () => {
if (ip && serial) {
fetchRequest(`http://${ip}/api-sdk/move_wheels?lw=0&rw=0&serial=${serial}`);
} else {
console.error('IP or serial is missing.');
}
};
const setIPAndSerial = () => {
if (ipInput && serialInput) {
setIp(ipInput);
setSerial(serialInput);
} else {
console.error('Please enter IP and serial.');
}
};
return (
<View style={styles.container}>
<ScrollView contentContainerStyle={styles.content}>
<Text style={styles.title}>Vector Control w/wirepod</Text>
<TextInput
style={styles.input}
label="Enter IP Address"
placeholder="IP of wire-pod"
value={ipInput}
onChangeText={text => setIpInput(text)}
/>
<TextInput
style={styles.input}
label="Enter Serial Number"
placeholder="Serial of Vector"
value={serialInput}
onChangeText={text => setSerialInput(text)}
/>
<Button title="Set IP and Serial" onPress={setIPAndSerial} style={styles.button} />
<Button title="Assume Behaviour Control" onPress={avec} style={styles.button} />
<Button title="Release Behaviour Control" onPress={rvec} style={styles.button} />
<Button title="Move Forward" onPress={fw} style={styles.button} />
<Button title="Move Left" onPress={left} style={styles.button} />
<Button title="Move Back" onPress={bc} style={styles.button} />
<Button title="Stop" onPress={stop} style={styles.button} />
</ScrollView>
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
},
content: {
width: '80%',
marginTop: '40%', // Adjust the margin to move content down
},
title: {
fontSize: 25,
fontWeight: 'bold',
marginBottom: 10,
},
input: {
marginBottom: 10,
width: '200 %',
borderWidth: 1,
padding: 8,
borderRadius: 5,
},
button: {
marginBottom: 10,
width: '100%',
padding: 10,
backgroundColor: 'blue',
borderRadius: 5,
justifyContent: 'center',
alignItems: 'center',
},
});
package.json:
{
"name": "wire-pod",
"version": "1.0.0",
"main": "node_modules/expo/AppEntry.js",
"scripts": {
"start": "expo start",
"android": "expo run:android",
"ios": "expo run:ios",
"web": "expo start --web"
},
"dependencies": {
"@react-native-community/blur": "^4.3.2",
"expo": "~49.0.15",
"expo-status-bar": "~1.6.0",
"native-base": "^3.4.28",
"react": "18.2.0",
"react-native": "0.72.6",
"react-native-gesture-handler": "~2.12.0",
"react-native-paper": "^5.11.1",
"react-native-reanimated": "~3.3.0",
"react-native-safe-area-context": "4.6.3",
"react-native-svg": "13.9.0",
"react-native-ui-lib": "^7.9.1",
"react-native-vector-icons": "^10.0.1",
"expo-splash-screen": "~0.20.5"
},
"devDependencies": {
"@babel/core": "^7.20.0"
},
"private": true
}
我使用 EAS 构建了一个 iOS 模拟器构建,构建成功并提供了 .app 文件,我使用众所周知的方法将其转换为 .ipa 文件。
答: 暂无答案
评论