我按照说明正确设置了CodePush . 首先,我推送到AppCenter:
$ appcenter codepush release-react -a myUser/appName -d Production
Detecting ios app version:
Using the target binary version value "1.0" from "ios/reactnative/Info.plist".
Running "react-native bundle" command:
node node_modules/react-native/local-cli/cli.js bundle --assets-dest /var/folders/gy/737c70fj7tq3pwdw758glxz00000gp/T/code-push118924-95814-1e6qqdj.df3g/CodePush --bundle-output /var/folders/gy/737c70fj7tq3pwdw758glxz00000gp/T/code-push118924-95814-1e6qqdj.df3g/CodePush/main.jsbundle --dev false --entry-file index.js --platform ios
Loading dependency graph, done.
bundle: Writing bundle output to: /var/folders/gy/737c70fj7tq3pwdw758glxz00000gp/T/code-push118924-95814-1e6qqdj.df3g/CodePush/main.jsbundle
bundle: Done writing bundle output
bundle: Copying 6 asset files
bundle: Done copying assets
Releasing update contents to CodePush:
Successfully released an update containing the "/var/folders/gy/737c70fj7tq3pwdw758glxz00000gp/T/code-push118924-95814-1e6qqdj.df3g/CodePush" directory to the "Production" deployment of the "appName" app.
其次,我访问AppCenter网站,选择成功推送的版本,并对每个应用程序进行强制推广 .
我试图重新启动应用程序,重新安装应用程序等...但应用程序不会从CodePush服务器更新 .
在我的XCode控制台中,我看到:
loading - codepush2018-10-24 12:10:10.837955+0200 reactnative[5546:3916480]
[CodePush] Loading JS bundle from file:///Users/myUser/Library/Developer/CoreSimulator/Devices/4E7D0B07-B6B2-4D3C-B5B8-F28F3DA47077/data/Containers/Bundle/Application/081FD17C-B182-488D-B2D1-C786A3B25AAB/reactnative.app/main.jsbundle
这是否意味着CodePush从本地加载?
我相信我正在运行 release
方案:
class App extends React.Component {
constructor(props){
super(props)
}
componentDidMount() {
codePush.sync({
updateDialog: true,
installMode: codePush.InstallMode.IMMEDIATE
});
}
render(){
return <Main screenProps={this.props} />
}
}
const codePushOptions = { checkFrequency: codePush.CheckFrequency.ON_APP_RESUME };
const ConnectedApp = codePush(codePushOptions)(connect(state => state)(App))
firebase.auth().onAuthStateChanged(auth => {
if(auth){
store.dispatch(setUser(auth))
}else{
store.dispatch(logout())
}
})
export default () => (
<Provider store={store}>
<ConnectedApp />
</Provider>
)
App安装时我也看不到 updateDialog: true
.
2 回答
有两种可能的解决方案可以避免这种冲突 .
定义单独的构建方案 .
添加一个自定义脚本,用于更改环境更改时的代码推送键 .
构建方案/类型
Android
Source
在
android/app/build.gradle
中,您可以定义各种buildTypes
并基于它构建应用程序IOS
在 Info 选项卡下,单击
Configurations
和Duplicate "Release" Configuration
中的+
按钮,并将其名称设置为Staging
现在,您可以配置
User Defined Settings
并定义新设置CODEPUSH_KEY
并将${CODEPUSH_KEY}
变量设置为不同的方案 .这里解释了详细步骤:Source
自定义脚本
或者,如果您不想添加更多构建方案/类型,则可以添加根据环境更改密钥的自定义脚本 .
change-environment.sh
现在你可以运行
.${SCRIPT_PATH}/change-environment.sh ${ENV}
示例:
./change-environment.sh staging
此脚本将android
buildTypes
和CODEPUSH_KEY
User Defined Settings 中的buildConfigField
更改为ios中的预定义方案 .将此脚本与
package.json
中的react native's packager start命令结合起来很方便CodePush
未完全加载,它从CodePush
服务器下载捆绑包 . 因此,您所看到的路径是模拟器文件系统的路径部分 .请参考此处了解如何设置部署目标
https://docs.microsoft.com/en-us/appcenter/distribution/codepush/react-native