React Native-从远程服务器下载JS包

时间:2019-05-24 15:03:38

标签: ios react-native

我正在构建一个React Native应用,我需要创建一个版本,该版本可以从我设置的S3存储桶中下载JS捆绑包,其中包含已捆绑的文件。

当前,该应用程序期望打包程序在localhost中运行,以便它可以从其中下载JS软件包,否则,它将在项目资源中查找main.jsbundle文件。

对于iOS,我尝试将else块中的返回值更改为S3存储桶的URL,但这没有用。如果我尝试在不运行打包程序的情况下启动应用程序,则会出现红屏,并显示一条错误消息,提示不存在捆绑软件网址。

// AppDelegate.m

...

- (NSURL *)sourceURLForBridge:(RCTBridge *)bridge
{
#if DEBUG
   return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index" fallbackResource:nil];
#else
  NSURL *bundleUrl = [[NSURL alloc] initWithString:@"http://my-s3-bucket.com/bundle.ios.js"];
  return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:bundleUrl];
 // return [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];
#endif
}

我知道项目中没有本地JS捆绑包供离线使用。那不是我现在要解决的问题。无论包装程序是否在运行,我都在尝试使该应用程序从我的S3存储桶中下载JS捆绑包。

0 个答案:

没有答案
相关问题