推送解决方案目前还是比较多的,有百度推送,个推,友盟,腾讯信鸽等,在实际应用中,我觉得极光推送这种免费的解决方案还是比较好的,
文档,推送到达效果,客服等都还算不错,所以这里极光官方插件集成到项目上的方法介绍下。
插件安装:
https://github.com/jpush/jpush-phonegap-plugin
cordova plugin add https://github.com/jpush/jpush-phonegap-plugin.git --variable API_KEY=your_jpush_appkey
文档,推送到达效果,客服等都还算不错,所以这里极光官方插件集成到项目上的方法介绍下。
插件安装:
https://github.com/jpush/jpush-phonegap-plugin
cordova plugin add https://github.com/jpush/jpush-phonegap-plugin.git --variable API_KEY=your_jpush_appkey
插件配置修改
在插件目录下src/android/JPushPlugin.java
将import your.package.name.R替换为import *****;
package即是config.xml中的widgetId
在插件目录下src/ios\PushConfig.plist ,修改对应的APP_KEY和CHANNEL(渠道)
<key>CHANNEL</key>
<string>App Store</string>
针对运行,安卓环境下提示缺少统计代码问题,解决办法如下:
在运行中会一直显示缺少统计代码,对java文件,文件位置 platforms/android/src/com/ionichina/ioniclub/MainActiovity.java文件作如下修改
import cn.jpush.android.api.JPushInterface; @Overrideprotected void onResume() { super.onResume(); JPushInterface.onResume(this); } @Override protected void onPause() { super.onPause(); JPushInterface.onPause(this);}
在使用中,方法请参考官方doc,这里贴下使用中的主要代码:
//启动极光推送服务
window.plugins.jPushPlugin.init();
//调试模式,这样报错会在应用中弹出一个遮罩层显示错误信息
window.plugins.jPushPlugin.setDebugMode(true);
var onReceiveNotification = function (event) {
try {
console.log('接收新的推送通知');
//var alert = event.aps.alert;//通知内容
window.plugins.jPushPlugin.setBadge(event.aps.badge);
console.log("JPushPlugin:onReceiveNotification key aps.alert:" + alert);
}
catch (exeption) {
console.log(exception)
}
};
//打开通知
var onOpenNotification = function (event) {
try {
console.log('打开通知消息');
window.plugins.jPushPlugin.setBadge(0);
window.plugins.jPushPlugin.resetBadge();
window.plugins.jPushPlugin.setApplicationIconBadgeNumber(0);
$state.go('app.bookshelf');
}
catch (exeption) {
console.log(exception)
}
};
document.addEventListener("jpush.receiveNotification", onReceiveNotification, false);
document.addEventListener("jpush.openNotification", onOpenNotification, false);