【问题标题】:Updating index.android.bundle from remote server in react native [Android]从远程服务器更新 index.android.bundle 反应原生 [Android]
【发布时间】:2018-01-09 22:37:14
【问题描述】:

我正在创建一个实现 aeroFS https://github.com/redbooth/react-native-auto-updater 库的演示反应原生应用程序 [aerofs 库不过是每次打开应用程序时都会检查远程服务器的更新,如果有更新,它将下载并要求用户在没有 Play 商店的情况下申请更新]。

到目前为止,应用程序能够下载文件,但下载后我看不到应用程序中的任何更改。我确定新下载的捆绑包没有在活动中使用。

在进一步检查库内部时,我在 ReactNativeAutoUpdaterActivity 类(主类)中发现了以下方法:-

@Override
@Nullable
public String getJSBundleFile() {
   updater=ReactNativeAutoUpdater.getInstance(this.getApplicationContext());
   updater.setMetadataAssetName(this.getMetadataAssetName());
   return updater.getLatestJSCodeLocation();
}

ReactNativeAutoUpdaterActivity 是从没有此方法的 ReactActivity 扩展而来的。我认为这已移至 ReactNativeHost,所以我知道这是问题所在,但现在我应该实现自己的 react 本机主机类来覆盖该方法,以便一旦新捆绑文件已下载,我可以将其应用到应用程序。

【问题讨论】:

  • 我仍然在为同样的问题苦苦挣扎,似乎没有人知道这一点。我需要做的就是从远程服务器获取 JSBundle,我很惊讶在本机反应中没有人需要这个。

标签: reactjs react-native


【解决方案1】:

MainApplication.java

import android.content.SharedPreferences;
import android.preference.PreferenceManager;
.
.
.
@Override
  public void onCreate(){
    super.onCreate();

    SharedPreferences preferences =
            PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
    preferences.edit().putString("debug_http_host", "128.xxx.xxx.xxx:1234").apply();
  }

使用远程虚拟机时,8081端口没有暴露,所以:

npm start -- --reset-cache --port=1234

AppDelegate.m (iOS):

jsCodeLocation = [NSURL URLWithString:@"http://128.xxx.xxx.xxx:1234/index.js"];

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-12-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多