插件文档的使用
http://microsoft.github.io/code-push/docs/getting-started.html
https://www.npmjs.com/package/cordova-plugin-code-push#installmode
https://my.oschina.net/u/783079/blog/674924
step1: 安装
终端安装code-push-cli
sudo npm install -g code-push -d
step2:注册 选择github 获取 key,写入到终端
![Paste_Image.png](http://upload-images.jianshu.io/upload_images/1764965-f827a9523190bcea.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
step3:创建新的code-push 应用
创建android的应用。code-push app add myapp_android
┌────────────┬───────────────────────────────────────┐
│ Name │ Deployment Key │
├────────────┼───────────────────────────────────────┤
│ Production │ FVqEweF8etZPuHTtUZ6p1xVIKOkHNkA7m31RM │
├────────────┼───────────────────────────────────────┤
│ Staging │ o28jGrUvqf2LT81MvXf2FbC_K7SyNkA7m31RM
创建ios的应用。code-push app add myapp_ios
Successfully added the "myapp_ios" app, along with the following default deployments:
┌────────────┬───────────────────────────────────────┐
│ Name │ Deployment Key │
├────────────┼───────────────────────────────────────┤
│ Production │ 0pUQJMvToiqK94DymbNqTt3zDqKtNkA7m31RM │
├────────────┼───────────────────────────────────────┤
│ Staging │ jTr9klk_n8oxthmnRPimUCTFx3PyNkA7m31RM │
step4:安装cordova插件
如果项目不存在,则ionic start newproject ,并安装cordova。
bower install ngCordova 安装 ngCordova
index.html 添加:
<script src="lib/ngCordova/dist/ng-cordova.js"></script>
<script src="cordova.js"></script>
cordova plugin add cordova-plugin-code-push
step5:配置config.xml 文件
将获取的staging的key替换。
<platform name="android">
<preference name="CodePushDeploymentKey" value="YOUR-ANDROID-DEPLOYMENT-KEY" />
</platform>
<platform name="ios">
<preference name="CodePushDeploymentKey" value="YOUR-IOS-DEPLOYMENT-KEY" />
</platform>
<access origin="*" />
step6: ionic plugin list 查看插件的安装列表 是否包含(code-push 和Whitelist)
step7:app.js 修改代码
$ionicPlatform.ready(function () {
//其他代码
window.codePush.sync(
function (syncStatus) {
switch (syncStatus) {
// Result (final) statuses
case SyncStatus.UP_TO_DATE:
navigator.notification.alert("软件又有所更新啦。", null, '提示', '棒棒的');
("软件又有所更新啦。", null, '提示', '棒棒的');
break;
case SyncStatus.ERROR:
navigator.notification.alert("软件自动更新失败,退出应用后,重新打开。", null, '提示', '我知道了');
break;
}
},
{
updateDialog: false, installMode: InstallMode.IMMEDIATE
}
);
//其他代码
})
step8: 代码添加到code-push
sudo code-push release-cordova myapp_android android