You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

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.plist in Xcode, add a new entry for App Transport Security Settings, then add a sub-entry Allow Arbitrary Loads and set it to YES. 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:
    lsof -i :8081
    
    If you see results, kill the process with:
    kill -9 <PID>
    
    Replace <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 node or 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 inet in Terminal, look for the inet line under your WiFi adapter). Then:
    1. Start the packager with:
      npm start -- --host 0.0.0.0
      
    2. In Xcode, open your project's debug configuration (or edit AppDelegate.m if you're using an older React Native version) and replace localhost with your local IP. For example:
      jsCodeLocation = [NSURL URLWithString:@"http://192.168.1.100:8081/index.bundle?platform=ios&dev=true"];
      
  • Reinstall dependencies: Windows and Mac can have subtle differences in node_modules. Delete your node_modules folder, package-lock.json (or yarn.lock), then run:
    npm install
    # Or yarn install
    
    This ensures you have Mac-compatible dependencies.
  • 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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.13 07:24:26