使用离线包在 iOS 设备上运行 react-native 应用程序 [英] Running react-native app on iOS device using offline bundle

查看:38
本文介绍了使用离线包在 iOS 设备上运行 react-native 应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

官方React Native 使用离线包在 iOS 设备上运行应用程序的文档说

The official React Native documentation to run app on iOS device using offline bundle says

打开 ios/YourApp/AppDelegate.m

Open ios/YourApp/AppDelegate.m

取消注释,jsCodeLocation = [[NSBundle mainBundle] ...

Uncomment the line, jsCodeLocation = [[NSBundle mainBundle] ...

使用最新的 react-native 0.30.0,此行不再出现在默认的 AppDelegate.m 文件中.摘自默认的 AppDelegate.m 文件

Using latest react-native 0.30.0, this line is no longer present in the default AppDelegate.m file. Excerpt from the default AppDelegate.m file

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

RCTRootView *rootView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation
                                                    moduleName:@"TestAppDelete"
                                             initialProperties:nil
                                                 launchOptions:launchOptions];

如果我尝试使用以前版本中的 jsCodeLocation,它会返回为 null

If I try to use the jsCodeLocation as it used to be in previous versions, it is returned as null

jsCodeLocation = [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];

我不知道为什么 main.jsbundle 的 URL 返回为 null.是不是不再由打包者创建了.如果还要使用最新版本创建,我该如何确认?

I am not sure why is the URL for main.jsbundle returned as null. Is it not created by the packager anymore. If it should be created using the latest version also, how can I confirm it?

如果您使用离线包在 iOS 设备上运行了 react-native 0.30.0 应用,请分享相关说明.

If you have run a react-native 0.30.0 app on an iOS device using offline bundle, please share the instructions to do so.

推荐答案

EDIT:在最新版本的 react-native 上,整个包 ip 检测应该是自动的.如果您在 xcode 上选择您的设备,请执行 build and run 并运行应用程序一次.它应该在手机上保存一个离线包,以便如果它没有找到正在运行的打包服务器,它将使用离线包.

EDIT: The whole bundle ip detection should be automatic on the latest release of react-native. If you select your device on xcode do build and run and run the app once. It should save an offline bundle on the phone so that if it doesn't find a packager server running, it will use the offline bundle.

来源:https://github.com/facebook/react-native/commit/8c29a52c529a52c54392ce52148e7d3aa9d

source: https://github.com/facebook/react-native/commit/8c29a52c54392ce52148e7d3aa9f835537453aa4

如果您在构建应用程序时更改为 release 方案,这将使用离线包编译您的应用程序.

If you change to a release scheme while building your app, that will compile your app with the offline bundle.

Product > Scheme > Edit Scheme > 将build configuration设置为Release.

Product > Scheme > Edit Scheme > set build configuration to Release.

不知道他们为什么不更新 Appdelegate.m 方法的文档.看起来这条线仍然存在于来源上.

Not sure why they didn't update the documentation for the Appdelegate.m method. Looks like the line is still there on the sources.

这篇关于使用离线包在 iOS 设备上运行 react-native 应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆