初始化階段:
1:npm install -g code-push-cli 安裝客戶端
2:code-push -v 查看是否安裝成功
3:code-push register 在codepush注冊賬號
4:code-push login
5:code-push app add <appName> <android/ios> react-native 添加app
例如code-push app add test android react-native
6:code-push app list 列出app列表
code-push deployment ls <appName> -k 查看APP的key
code-push deployment history <appName> Porduction/Staging
例如:code-push deployment history test Production
7:yarn add react-native-code-push 在rn項目下安裝codepush
8:react-native link react-native-code-push 鏈接codepush
其他命令:
https://github.com/Microsoft/code-push/blob/master/cli/README-cn.md
配置階段
Android:
1:項目settings.build
include ':react-native-code-push'project(':react-native-code-push').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-code-push/android/app')
2:App/build.gradle
3:MainApplication里面
@Nullable@Overrideprotected String getJSBundleFile() { return CodePush.getJSBundleFile();}@Overridepublic boolean getUseDeveloperSupport() { return BuildConfig.DEBUG;}@Overrideprotected List<ReactPackage> getPackages() { return Arrays.<ReactPackage>asList( new MainReactPackage(), new CodePush(“CODEPUSH_KEY”, MainApplication.this, BuildConfig.DEBUG) );}
ios配置階段:
yarn add react-native-code-push
react-native link react-native-code-push
然后找到info.plist文件
CodePushDeploymentKey 填入codekey
ios目前不能再debug模式測試更新 因為會一直加載本地jsbundle 覆蓋下載后的早直,所以看不到效果。
測試iOS:
打開 AppDelegate.m文件
1:修改:
jsCodeLocation = [CodePush bundleURL];//#ifdef DEBUG//// jsCodeLocation = [NSURL URLWithString:@"http://localhost:8081/index.ios.bundle?platform=ios&dev=true"];// jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index.ios"fallbackResource:nil];//#else// jsCodeLocation = [CodePush bundleURL];//#endif//
2:打開node_modules/react-native/scripts/react-native-code.sh 17-20
if [[ "$PLATFORM_NAME" = "iphonesimulator" ]]; then # echo "Skipping bundling for Simulator platform" # exit 0; # fi
3:重新react-native run-ios
然后再次熱更新即可成功測試呻畸。
issue:
https://github.com/Microsoft/react-native-code-push/issues/941
JS端:
import codePush from 'react-native-code-push'componentDidMount(){CodePush.sync({ updateDialog: { mandatoryContinueButtonLabel:'更新', mandatoryUpdateMessage:'有新版本了,請您及時更新', optionalIgnoreButtonLabel: '稍后', optionalInstallButtonLabel: '后臺更新', optionalUpdateMessage: '有新版本了猩谊,是否更新曹步?', title: '更新提示' }, installMode: CodePush.InstallMode.IMMEDIATE});}
使用階段:
發(fā)布熱更新命令
code-push release-react test android --t 1.0.0 --dev false --d Production --des "更新描述” --m true
test:注冊codepush時APP的名字
android:平臺 Android/ios
t :要對那個版本進(jìn)行熱更新這里是對1.0.0進(jìn)行更新
dev:是否是開發(fā)者模式
d:staging/production
des: 更新描述
m:是否強(qiáng)制升級
輸入命令后會自動打包生產(chǎn)文件上傳到codepush上面
提示:
1:iOS和android最好將版本號改為x.x.x形式
2:使用staging時貌似成功幾率很低
3:"react-native-code-push":"^4.1.0-beta",
截圖:
參考:
http://blog.csdn.net/fengyuzhengfan/article/details/52003798
https://github.com/Microsoft/react-native-code-push