React Native项目iOS端Xcode运行报错及Mac端加载失败求助
解决React Native跨平台运行的两个常见问题
Hey there, let's break down these two React Native headaches you're dealing with—they're pretty typical when moving between Windows/Mac or iOS/Android, so let's work through each one:
问题1:iOS设备上通过Xcode运行React Native项目时出现错误代码-999
Error -999 usually ties into network or cache issues. Here are the fixes I'd recommend trying in order:
- Check App Transport Security (ATS) settings: Open your project's
Info.plistin Xcode, add a new entry forApp Transport Security Settings, then add a sub-entryAllow Arbitrary Loadsand set it toYES. This bypasses strict network restrictions that might block the dev server connection (note: this is only for debug builds—lock this down for release versions). - Clear React Native's cache: Run this in your project directory to reset the packager cache:
npm start -- --reset-cache # Or if you use yarn yarn start --reset-cache - Fully restart your tools: Quit Xcode completely, shut down the iOS simulator/device, kill any running Node processes, then restart everything. Sometimes stuck processes just need a fresh start.
- Verify port 8081 isn't blocked: Use this command to check if anything's using the default dev port:
If you see results, kill the process with:lsof -i :8081
Replacekill -9 <PID><PID>with the process ID from the previous output.
问题2:Windows开发安卓后,Mac上Xcode运行时bundle无法连接开发服务器
Since you've already tried killing 8081 processes and modifying localhost, let's try these less obvious fixes:
- Check Mac's firewall settings: Open System Settings → Network → Firewall → Options. Make sure
nodeor the React Native Packager is allowed to receive incoming connections. If it's not listed, click the "+" button, navigate to your Node installation (usually/usr/local/bin/node), and add it. - Use your local IP instead of localhost: Sometimes localhost resolution flubs up across networks. First, find your Mac's local IP (run
ifconfig | grep inetin Terminal, look for theinetline under your WiFi adapter). Then:- Start the packager with:
npm start -- --host 0.0.0.0 - In Xcode, open your project's debug configuration (or edit
AppDelegate.mif you're using an older React Native version) and replacelocalhostwith your local IP. For example:jsCodeLocation = [NSURL URLWithString:@"http://192.168.1.100:8081/index.bundle?platform=ios&dev=true"];
- Start the packager with:
- Reinstall dependencies: Windows and Mac can have subtle differences in node_modules. Delete your
node_modulesfolder,package-lock.json(oryarn.lock), then run:
This ensures you have Mac-compatible dependencies.npm install # Or yarn install - Confirm your device is on the same network: If you're using a physical iOS device, make sure it's connected to the same WiFi network as your Mac. If you're using a simulator, double-check that it's not using a virtual network isolated from your Mac.
内容的提问来源于stack exchange,提问作者priti narang
相关产品推荐
相关产品推荐

