React Native codePush rollback after restart
我正在尝试实施AppCenter CodePush来更新Javascript代码,而不必经过App Store审查过程。
我已经按照此处提到的iOS和Android步骤来设置多部署环境:
https://github.com/microsoft/react-native-code-push/blob/master/docs/multi-deployment-testing-ios.md
https://github.com/microsoft/react-native-code-push/blob/master/docs/multi-deployment-testing-android.md
版本
我在使用
我做了一个codePush版本,如下所示:
componentDidMount
1 2 3 4 5 6 7 8 | componentDidMount() { codePush.notifyApplicationReady(); ... codePush.sync({ updateDialog: true, installMode: codePush.InstallMode.IMMEDIATE }); } |
导出应用程序
1 2 3 4 5 | App = codePush({ checkFrequency: codePush.CheckFrequency.ON_APP_RESUME })(App); AppRegistry.registerComponent("myApp", () => App); |
Info.plist
android / app / build.gradle
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | buildTypes { debug { buildConfigField"String","CODEPUSH_KEY", '""' } releaseStaging { buildConfigField"String","CODEPUSH_KEY", '"my_code"' matchingFallbacks = ['release'] } release { minifyEnabled enableProguardInReleaseBuilds proguardFiles getDefaultProguardFile("proguard-android.txt"),"proguard-rules.pro" signingConfig signingConfigs.release buildConfigField"String","CODEPUSH_KEY", '"my_code"' } } |
我的构建设置包含codePush Release和登台代码。
我还尝试将CodePush Staging版本升级到生产环境,但这并不能解决我的问题。
更新
批准成功更新应用程序后,它要求更新应用程序。但是,当我重新启动该应用程序时,它会回滚到以前的版本。
更新2
AppDelgate.m的更改:
1 2 3 4 5 6 7 | #import <CodePush/CodePush.h> #if DEBUG return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index" fallbackResource:nil]; #else return [CodePush bundleURL]; #endif |
MainApplication.java更改:
1 2 3 4 5 6 7 8 9 10 11 | import com.microsoft.codepush.react.CodePush; @Override protected String getJSBundleFile() { return CodePush.getJSBundleFile(); } @Override protected List<ReactPackage> getPackages() { return Arrays.<ReactPackage>asList( .. new CodePush(BuildConfig.CODEPUSH_KEY, MainApplication.this, BuildConfig.DEBUG), |
build.gradle更改:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | buildTypes { debug { buildConfigField"String","CODEPUSH_KEY", '""' } releaseStaging { buildConfigField"String","CODEPUSH_KEY", '"<staging_key>"' matchingFallbacks = ['release'] } release { .. buildConfigField"String","CODEPUSH_KEY", '"<prod_key>"' } } |
您是否正在模拟器中对此进行测试?
如果是这样,执行
如果您在模拟器中运行,CodePush的行为将与未绑定到打包程序的真实设备的行为有所不同。最好的测试方法是进行构建并将该构建上传到商店以分发到您的测试池。
然后,您可以通过Google Play商店或testflight for iOS下载并安装内部版本,并在此处测试您的CodePush安装。
编辑:
聊天后,对以下代码进行了更改,我们可以正常工作:
首先,创建一个options对象,并将其用于我们的codePush调用中:
1 2 3 4 5 | const options = { updateDialog: true, installMode: codePush.InstallMode.IMMEDIATE, checkFrequency: codePush.CheckFrequency.ON_APP_RESUME }; |
然后我们可以调用codePush sync,如下所示:
最后,我们没有将codePush设置分配给
1 2 3 | AppRegistry.registerComponent("myApp", () => codePush(options)(App) ); |
不是不是CodePush专家,我不知道是否需要选项部分,尽管我认为在不同点使用不同的选项可能会导致不一致。
我确实认为调用
无论哪种方式,这两件事的结合都解决了该问题。
我遇到了同样的问题,所以我只是在我的应用着陆页上写下了codePush.notifyAppReady(),并确保在检查新更新之前先做了
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | componentDidMount(): void { codePush.notifyAppReady() this.checkUpdate(); } checkUpdate = async () => { const updateData: RemotePackage | null = await codePush.checkForUpdate() if (updateData && !updateData.failedInstall) { //your code this.setState({ isMandatory: updateData.isMandatory, whatsNew: updateData.description, showAppUpdateDialog: true }) } } |