React native 使用脱机捆绑包在iOS设备上运行react本机应用程序

React native 使用脱机捆绑包在iOS设备上运行react本机应用程序,react-native,React Native,使用离线捆绑包在iOS设备上运行应用程序的官方文档中说 打开ios/YourApp/AppDelegate.m 取消对行的注释,jsCodeLocation=[[NSBundle mainBundle] 使用最新的react native 0.30.0,此行不再出现在默认的AppDelegate.m文件中。从默认的AppDelegate.m文件中摘录 NSURL*jsCodeLocation; jsCodeLocation=[[RCTBundleURLProvider sharedSetting

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

打开ios/YourApp/AppDelegate.m

取消对行的注释,jsCodeLocation=[[NSBundle mainBundle]

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

NSURL*jsCodeLocation;
jsCodeLocation=[[RCTBundleURLProvider sharedSettings]jsBundleURLForBundleRoot:@“index.ios”fallbackResource:nil];
RCTRootView*rootView=[[RCTRootView alloc]initWithBundleURL:jsCodeLocation
moduleName:@“TestAppDelete”
initialProperties:无
启动选项:启动选项];
如果我尝试像在以前的版本中一样使用
jsCodeLocation
,它将返回为null

jsCodeLocation=[[NSBundle mainBundle]URLForResource:@“main”带扩展名:@“jsbundle”];
我不确定为什么
main.jsbundle
的URL返回为
null
。它不再是由打包商创建的。如果它也应该使用最新版本创建,我如何确认它


如果您使用脱机捆绑包在iOS设备上运行了一个
react-native 0.30.0
应用程序,请分享执行此操作的说明。

编辑:在最新版本的react-native上,整个捆绑包ip检测应该是自动的。如果您在xcode上选择您的设备,请执行
构建并运行
并运行该应用程序一次。它应该ld在手机上保存一个脱机捆绑包,以便在未找到正在运行的packager服务器时使用该脱机捆绑包

资料来源:


如果您在构建应用程序时更改为
发布
方案,则将使用脱机捆绑包编译您的应用程序

产品>方案>编辑方案>将
构建配置设置为
发布


不确定他们为什么没有更新
Appdelegate.m
方法的文档。看起来该行仍然在源代码上。[编辑:这有一个问题]

当我在ShadowsocksX中打开全局代理时,自动IP检测不会返回
http://localhost:8081/index.ios.bundle
处于调试模式。 这就是main.jsbundle的URL返回为
null
的原因

如何解决?

备选案文1:

替换

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

jsCodeLocation=[NSURL URLWithString:@”http://localhost:8081/index.ios.bundle?platform=ios&dev=true"];
此方法可以禁用自动IP检测

备选案文2:


如果打开全局代理模式,请切换代理模式。

我唯一可以使用的react-native 0.37修复方法是回到AppDelegate.m中手动编辑jsCodeLocation的“老派”方法。调试又好了

确保您的设备和开发机器在同一个wi-fi上,并可能断开任何有线以太网,直到它正常工作

-(BOOL)应用程序:(UIApplication*)应用程序使用选项完成启动:(NSDictionary*)启动选项
{
NSURL*jsCodeLocation;
//注释掉,无法通过错误:未实现loadSourceForBridge时bundleURL必须为非nil
//jsCodeLocation=[[RCTBundleURLProvider sharedSettings]jsBundleURLForBundleRoot:@“index.ios”fallbackResource:nil];
#如果调试
NSLog(@“AppDelegate:DEBUG”);
#if TARGET_IPHONE_模拟器
NSLog(@“AppDelegate:DEBUG:TARGET_IPHONE_模拟器”);
jsCodeLocation=[NSURL URLWithString:@”http://localhost:8081/index.ios.bundle"];
#否则
NSLog(@“AppDelegate:DEBUG:!TARGET_IPHONE_SIMULATOR”);
NSLog(@“要进行设备调试,请打开RCTWebSocketExecutor.m并用MacBook IP替换本地主机。”);
//获取开发人员主机IP地址:
//ifconfig | grep inet\| tail-1 | cut-d”“-f2
jsCodeLocation=[NSURL URLWithString:@”http://192.16.29.213:8081/index.ios.bundle"];
#恩迪夫
#否则
NSLog(@“AppDelegate:RELEASE jsbundle”);
jsCodeLocation=[[NSBundle mainBundle]URLForResource:@“main”带扩展名:@“jsbundle”];
#恩迪夫
NSLog(@“jsCodeLocation=%@”,jsCodeLocation);
RCTRootView*rootView=[[RCTRootView alloc]initWithBundleURL:jsCodeLocation
moduleName:@“蓝牙连接”
initialProperties:无
启动选项:启动选项];
rootView.backgroundColor=[[UIColor alloc]initWithRed:1.0f绿色:1.0f蓝色:1.0f alpha:1];
self.window=[[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];
UIViewController*rootViewController=[UIViewController新建];
rootViewController.view=rootView;
self.window.rootViewController=rootViewController;
[self.window makeKeyAndVisible];
返回YES;
}

tl;dr确保您的本地主机ip地址在主机文件中明确说明,并且主机文件没有损坏

因此,我们的团队一直在关注这个问题。结果表明,React Native读取您机器上的主机文件,查找要存储的URL,这样它就可以拉动js来创建脱机捆绑包,或者在应用程序在您的设备上运行时直接访问打包程序

实际上,我们并没有试图将其作为脱机捆绑包运行,只是在ios模拟器中运行,因此我们非常头疼。我们找到了修复程序,因为所需的修复程序也导致了react native的其他问题。我们在mac上的etc/hosts文件没有明确说明localhost ip。我在中添加了这一点,问题似乎消失了y、 原谅我,因为我对osx和dns解析不太了解,但似乎有了新的au
Signing for "<app name>" requires a development team. 
Select a development team in the project editor.