问题描述:通过后台发送通知给个人。
解决方法:
1 新建账号
https://www.jiguang.cn/
2 安装插件
cordova-plugin-jcore 1.1.11
jpush-phonegap-plugin 3.2.13
cordova pluign add [email protected]
cordova plugin add [email protected] --variable API_KEY=34c81aa4261113f51df4542f
**如果安装插件的时候如果没有对应版本号安装会出现确定版本已经安装成功,获取不到对应的唯一标识,推送无反应等情况**
3 相关对应代码
```
$scope.messagejush = "on load view success!";
var onDeviceReady = function () {
$timeout(function () {
$scope.messagejush += "JPushPlugin:Device ready!";
})
initiateUI();
};
var onOpenNotification = function (event) {
try {
var alertContent;
if (device.platform == "Android") {
alertContent = window.plugins.jPushPlugin.openNotification.alert;
alertCode = window.plugins.jPushPlugin.receiveMessage.extras.code
} else {
alertContent = event.aps.alert;
}
$timeout(function () {
$scope.messagejush += alertContent;
})
//通过推送消息添加标识来跳转对应页面
alert("推送消息:" + alertContent);
if(alertCode=='work'){
location.href='#/tab/work'
}
} catch (exception) {
console.log("JPushPlugin:onOpenNotification" + exception);
}
};
var onReceiveNotification = function (event) {
try {
var alertContent;
if (device.platform == "Android") {
alertContent = window.plugins.jPushPlugin.receiveNotification.alert;
} else {
alertContent = event.aps.alert;
}
$timeout(function () {
$scope.messagejush += alertContent;
$scope.notificationResult = alertContent;
})
} catch (exception) {
console.log(exception)
}
};
var onReceiveMessage = function (event) {
try {
var messagejush;
if (device.platform == "Android") {
messagejush = window.plugins.jPushPlugin.receiveMessage.messagejush;
} else {
messagejush = event.content;
}
$timeout(function () {
$scope.messagejush += messagejush;
$scope.messageResult = messagejush;
})
} catch (exception) {
console.log("JPushPlugin:onReceiveMessage-->" + exception);
}
};
// 获取RegistrationID
var getRegistrationID = function () {
window.plugins.jPushPlugin.getRegistrationID(function (data) {
try {
if (data.length == 0) {
var t1 = window.setTimeout(getRegistrationID, 1000);
}
$timeout(function () {
$scope.messagejush+= "JPushPlugin:registrationID is " + data;
})
$scope.registrationID = data;
var sessionNews = ""
sessionNews = datadService.getObject('loginData')
datadService.setObject('registrationID',$scope.registrationID)
} catch (exception) {
console.log(exception);
}
},function(err){
alert(err)
});
};
var initiateUI = function () {
try {
window.plugins.jPushPlugin.init();
getRegistrationID();
if (device.platform != "Android") {
window.plugins.jPushPlugin.setDebugModeFromIos();
window.plugins.jPushPlugin.setApplicationIconBadgeNumber(0);
} else {
window.plugins.jPushPlugin.setDebugMode(true);
window.plugins.jPushPlugin.setStatisticsOpen(true);
}
$timeout(function () {
$scope.messagejush += '初始化成功! \r\n';
})
} catch (exception) {
console.log(exception);
}
}
document.addEventListener("deviceready", onDeviceReady, false);
document.addEventListener("jpush.openNotification", onOpenNotification, false);
document.addEventListener("jpush.receiveNotification", onReceiveNotification, false);
document.addEventListener("jpush.receiveMessage", onReceiveMessage, false);
```
4 最后别忘了依赖注入插件