我找不到最新版本React-Native的文档,无法了解如何将应用程序捆绑并部署到实际设备上。
在我的iPhone上打开远程调试器时,我遇到了红屏错误,但是如果没有启用远程调试器,则应用程序会加载。
我没有更改AppDelegate.m
中的任何网址,根Bundle仍然是@"index.ios"
。
我找不到最新版本React-Native的文档,无法了解如何将应用程序捆绑并部署到实际设备上。
在我的iPhone上打开远程调试器时,我遇到了红屏错误,但是如果没有启用远程调试器,则应用程序会加载。
我没有更改AppDelegate.m
中的任何网址,根Bundle仍然是@"index.ios"
。
感谢Monochrome的回答,对我很有帮助!
从第4步开始我遇到了问题,我的AppDelegate.m文件看起来和你所解释的不太一样。
jsCodeLocation = [[RCTBundleURLProvider sharedSettings]
jsBundleURLForBundleRoot:@"index.ios" fallbackResource:nil];
RCTRootView *rootView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation
moduleName:@"Kompas"
initialProperties:nil
launchOptions:launchOptions];
我自己也是RN开发的初学者,第一次尝试在真机上运行应用时遇到了同样的问题。在这里,我想与大家分享我是如何最终解决这个问题的:
So firstly, make sure that your iPhone (or iPad) is connected to your Mac via the cable;
Then check if both your Mac and iPhone are connected to the same Wi-Fi network;
Then comes the tricky part. If you are using RN ver < 0.30, you have to configure your Info.plist file properly. To be clear, you have to disable such thing as App Transport Security (ATS). This is a security feature in iOS 9 which will block any unauthorized network activity that may happen on your smartphone, to keep it simple. The sad part is that ATS considers launching a RN app to be that kind of activity and blocks it. So you have to open your Info.plist file and add this code, officially proved by the Facebook team:
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
You might wonder why you don't see it in the Docs now – well, as far as I know, this is because in RN ver 0.30 they made ATS disabled by default (you can read about it in the bottom of the page)
Now you need to open your AppDelegate.m file and find this line:
jsCodeLocation = [NSURL URLWithString:@"http://localhost:8081/index.ios.bundle?platform=ios&dev=true"];
Uncomment it and then change it to look like that:
jsCodeLocation = [NSURL URLWithString:@"http://Your.Mac's_Ip.Address.Here:8081/index.ios.bundle?platform=ios&dev=true"];
Like that:
jsCodeLocation = [NSURL URLWithString:@"http://255.255.255.255:8081/index.ios.bundle?platform=ios&dev=true"];
Then go to your simulator choosing list (idk how it is called, actually, just take a look at my screenshot :D ) and choose your connected device.