React Native using pre-bundled file on device, even if DEV-mode

前端 未结 7 926
南笙
南笙 2020-12-30 20:05

A few days ago, when I build and run my react native app from Xcode on a device, I realised that even if I set my scheme to Debug, the app is still loading from a pre-bundle

相关标签:
7条回答
  • 2020-12-30 20:24

    so your problem is here:

    Change code in your AppDelegate.m:

    jsCodeLocation = [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"]; // comment this line
    
    jsCodeLocation = [NSURL URLWithString:@"http://xxx.xxx.x.xx:8081/index.ios.bundle?platform=ios&dev=true"]; //uncomment this line  
    

    Cheers:)

    0 讨论(0)
  • 2020-12-30 20:25

    As i have faced same problem and above points didn't work for me. i got it worked by doing these steps.

    • Go to xcode-> your project-> info.plist
    • In "App Transport Security settings" make "Allow Arbitrary Loads" Yes.

    it should fix this issue.

    0 讨论(0)
  • 2020-12-30 20:28

    For those who are connected to the same Wi-Fi, but to a different IP address than localhost (you've set it up in RCTWebSocketExecutor.m):

    Check Xcode debug console, if you can find the following error:

    App Transport Security has blocked a cleartext HTTP (http://) resource load since it is insecure. Temporary exceptions can be configured via your app's Info.plist file.
    
    1. Use the following answer: https://stackoverflow.com/a/32704702/3979621

    2. And then use Codesingh's answer. BTW I recommend using the #ifdef DEBUG directive as follows, so that you don't have to change it manually when switching between build variants:

    .

    #ifdef DEBUG
      jsCodeLocation = [NSURL URLWithString:@"http://xxx.xxx.xxx.xxx:8081/index.ios.bundle?platform=ios&dev=true"];
    #else
      jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index.ios" fallbackResource:nil];
    #endif
    
    0 讨论(0)
  • 2020-12-30 20:30

    For me, I had accidentally clicked Deny instead of Allow on a macos popup asking whether to accept incoming network connections to «node».

    Opening System Preferences -> Security & Privacy -> Firewall -> Firewall options, and finding the line for node that was set to block, then correcting it to allow solved my problem!

    0 讨论(0)
  • 2020-12-30 20:38

    in my case it was a (for react native) unexpected networksetting, so it grepped the wrong ip.

    Check the Build report if your ip is correctly detected

    react native docs

    0 讨论(0)
  • 2020-12-30 20:39

    For me, this happened after updating my mac to Mojave. Turns out that with the update the firewall settings changed to block all incoming connections... Thank you Stian Jensen for getting me on the track of checking my firewall!

    What I did:

    1. Open System Preferences -> Security & Privacy -> Firewall -> Firewall options
    2. Uncheck "Block all incoming connections"
    3. Make sure that the connections listed are from sources that you trust
    0 讨论(0)
提交回复
热议问题