3

I have a react native app, if I run it on the iOS simulator it works and can connect to the running packager that is running on localhost:8081, however if I try to run the app on an actual iOS device, it fails because it can't load the js bundle because it can't find the packager service.

My device and my dev server are on the same WIFI network, how does the app determine where the pacakger service lives? If I modify the AppDelegate.m file and replace:

jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index.ios" fallbackResource:nil];

//with an explicit IP address, then the app works:

jsCodeLocation = [NSURL URLWithString:@"http://192.168.0.9:8081/index.ios.bundle?platform=ios&dev=true"];

Any tips on settings I may need to modify for running on an actual device, without having to explicitly modify this file.

Thanks.

jose920405
  • 7,982
  • 6
  • 45
  • 71
Mark D
  • 526
  • 6
  • 10

2 Answers2

0

I've managed to temporarily fix this issue by adding this to the Info.plist file.

<key>NSAllowsArbitraryLoads</key>
<true/>
<key>NSAllowsArbitraryLoadsInWebContent</key>
<true/>
<key>NSAllowsLocalNetworking</key>
<true/>
Sidharth
  • 1,675
  • 1
  • 15
  • 23
0

I was traveling this problem for a long time and see the problem is related with IOS iphone Emulator. This is the solution for me, is easy and not forcing the code:

This solution is for iphone simulator, you don't have this error on physical iphone

  1. Run the app on xcode or npm/yarn
  2. Once the app is opened on the simulator press: CMD + D
  3. Clip on “Configure Bundler”
  4. Now you have 3 inputs:
  5. ID: 0.0.0.0: Replace 127.0.0.1
  6. PORST: 8081: Replace: 8081
  7. Last input: Index: empty