mirror of
https://github.com/jpush/jpush-phonegap-plugin.git
synced 2025-02-08 03:42:52 +08:00
demo add openNotification receiveNotification receiveMessage code
This commit is contained in:
parent
2510289d95
commit
7545a948bd
@ -14,6 +14,17 @@
|
|||||||
console.log("JPushPlugin:Device ready!")
|
console.log("JPushPlugin:Device ready!")
|
||||||
initiateUI();
|
initiateUI();
|
||||||
}
|
}
|
||||||
|
var onGetRegistradionID = function(data) {
|
||||||
|
try{
|
||||||
|
console.log("JPushPlugin:registrationID is "+data)
|
||||||
|
|
||||||
|
$("#registrationid").html(data);
|
||||||
|
}
|
||||||
|
catch(exception){
|
||||||
|
console.log(exception);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var onTagsWithAlias = function(event){
|
var onTagsWithAlias = function(event){
|
||||||
try{
|
try{
|
||||||
console.log("onTagsWithAlias");
|
console.log("onTagsWithAlias");
|
||||||
@ -29,8 +40,8 @@
|
|||||||
var onOpenNotification = function(event){
|
var onOpenNotification = function(event){
|
||||||
try{
|
try{
|
||||||
|
|
||||||
var alert = event.aps.alert;
|
var alertContent = event.aps.alert;
|
||||||
console.log("JPushPlugin:onPpenNotification key aps.alert:"+alert);
|
alert("open Notificaiton:"+alertContent);
|
||||||
}
|
}
|
||||||
catch(exception){
|
catch(exception){
|
||||||
console.log("JPushPlugin:onPpenNotification"+exception);
|
console.log("JPushPlugin:onPpenNotification"+exception);
|
||||||
@ -38,51 +49,59 @@
|
|||||||
}
|
}
|
||||||
var onReceiveNotification = function(event){
|
var onReceiveNotification = function(event){
|
||||||
try{
|
try{
|
||||||
var alert = event.aps.alert;
|
|
||||||
console.log("JPushPlugin:onReceiveNotification key aps.alert:"+alert);
|
var eventContent="{";
|
||||||
|
for(var key in event){
|
||||||
|
if(key=="type"){
|
||||||
|
break
|
||||||
|
}
|
||||||
|
eventContent+=key+":"+JSON.stringify(event[key])+"\n"
|
||||||
|
}
|
||||||
|
eventContent+="}";
|
||||||
|
$("#notificationResult").html(eventContent);
|
||||||
|
|
||||||
}
|
}
|
||||||
catch(exeption){
|
catch(exeption){
|
||||||
console.log(exception)
|
console.log(exception)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
var onReceiveMessage = function(event){
|
||||||
var onGetRegistradionID = function(data) {
|
|
||||||
try{
|
try{
|
||||||
console.log("JPushPlugin:registrationID is "+data)
|
|
||||||
|
|
||||||
$("#registrationid").html(data);
|
var eventMessage="{";
|
||||||
|
for(var key in event){
|
||||||
|
if(key=="type"){
|
||||||
|
break
|
||||||
|
}
|
||||||
|
eventMessage+=key+":"+JSON.stringify(event[key])+"\n"
|
||||||
|
console.log(key+":"+JSON.stringify(event[key]));
|
||||||
|
|
||||||
|
}
|
||||||
|
eventMessage+="}";
|
||||||
|
$("#messageResult").html(eventMessage);
|
||||||
|
|
||||||
}
|
}
|
||||||
catch(exception){
|
catch(exception){
|
||||||
console.log(exception);
|
console.log("JPushPlugin:onReceiveMessage"+exception);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var initiateUI = function(){
|
var initiateUI = function(){
|
||||||
|
|
||||||
try{
|
try{
|
||||||
window.plugins.jPushPlugin.init();
|
window.plugins.jPushPlugin.init();
|
||||||
window.plugins.jPushPlugin.setDebugMode(true);
|
|
||||||
window.plugins.jPushPlugin.getRegistrationID(onGetRegistradionID);
|
window.plugins.jPushPlugin.getRegistrationID(onGetRegistradionID);
|
||||||
window.plugins.jPushPlugin.setApplicationIconBadgeNumber(5);
|
|
||||||
// var extras={"name":"json"};
|
if(JPushPlugin.prototype.isPlatformIOS()){
|
||||||
// window.plugins.jPushPlugin.addLocalNotification(1,"hh","ln",1111,1000*60,extras);
|
window.plugins.jPushPlugin.setDebugModeFromIos();
|
||||||
// window.plugins.jPushPlugin.removeLocalNotification(1111);
|
window.plugins.jPushPlugin.setApplicationIconBadgeNumber(0);
|
||||||
// window.plugins.jPushPlugin.clearLocalNotifications();
|
}else{
|
||||||
|
window.plugins.jPushPlugin.setDebugMode(true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch(exception){
|
catch(exception){
|
||||||
console.log(exception);
|
console.log(exception);
|
||||||
}
|
}
|
||||||
|
|
||||||
//test android interface
|
|
||||||
//window.plugins.jPushPlugin.stopPush()
|
|
||||||
//window.plugins.jPushPlugin.resumePush();
|
|
||||||
//window.plugins.jPushPlugin.clearAllNoticication();
|
|
||||||
//window.plugins.jPushPlugin.setLatestNotificationNum(5);
|
|
||||||
//window.plugins.jPushPlugin.stopPush();
|
|
||||||
//window.plugins.jPushPlugin.isPushStopped(onIsPushStopped);
|
|
||||||
//window.plugins.jPushPlugin.init();
|
|
||||||
//window.plugins.jPushPlugin.setDebugMode(true);
|
|
||||||
//window.plugins.jPushPlugin.startLogPageView("mianPage");
|
|
||||||
|
|
||||||
$("#setTagWithAliasButton").click(function(ev) {
|
$("#setTagWithAliasButton").click(function(ev) {
|
||||||
try{
|
try{
|
||||||
var tag1 = $("#tagText1").attr("value");
|
var tag1 = $("#tagText1").attr("value");
|
||||||
@ -112,11 +131,14 @@
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
document.addEventListener("jpush.receiveNotification", onReceiveNotification, false);
|
|
||||||
document.addEventListener("jpush.setTagsWithAlias", onTagsWithAlias, false);
|
document.addEventListener("jpush.setTagsWithAlias", onTagsWithAlias, false);
|
||||||
document.addEventListener("deviceready", onDeviceReady, false);
|
document.addEventListener("deviceready", onDeviceReady, false);
|
||||||
document.addEventListener("jpush.openNotification", onOpenNotification, false);
|
document.addEventListener("jpush.openNotification", onOpenNotification, false);
|
||||||
|
document.addEventListener("jpush.receiveNotification", onReceiveNotification, false);
|
||||||
|
document.addEventListener("jpush.receiveMessage", onReceiveMessage, false);
|
||||||
|
|
||||||
|
|
||||||
|
//jpush.receiveMessage
|
||||||
</script>
|
</script>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
@ -164,8 +186,19 @@
|
|||||||
<input type="button" id="setTagWithAliasButton" value="Add tag and alias" />
|
<input type="button" id="setTagWithAliasButton" value="Add tag and alias" />
|
||||||
</div>
|
</div>
|
||||||
<div data-role="fieldcontain">
|
<div data-role="fieldcontain">
|
||||||
|
<label id="tagAliasPrompt" >设置tag/alias结果: </label>
|
||||||
<label id="tagAliasResult" >null</label>
|
<label id="tagAliasResult" >null</label>
|
||||||
</div>
|
</div>
|
||||||
|
<div data-role="fieldcontain">
|
||||||
|
<label id="notificationPrompt" >接受的通知内容:</label>
|
||||||
|
<label id="notificationResult" >null</label>
|
||||||
|
</div>
|
||||||
|
<div data-role="fieldcontain">
|
||||||
|
<label id="messagePrompt" >接受的自定义消息:</label>
|
||||||
|
<label id="messageResult" >null</label>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
@ -296,8 +296,11 @@ static NSDictionary *_luanchOptions=nil;
|
|||||||
|
|
||||||
dispatch_async(dispatch_get_main_queue(), ^{
|
dispatch_async(dispatch_get_main_queue(), ^{
|
||||||
|
|
||||||
|
[self.commandDelegate evalJs:[NSString stringWithFormat:@"cordova.fireDocumentEvent('jpush.receiveMessage',%@)",jsonString]];
|
||||||
|
|
||||||
[self.commandDelegate evalJs:[NSString stringWithFormat:@"window.plugins.jPushPlugin.receiveMessageIniOSCallback('%@')",jsonString]];
|
[self.commandDelegate evalJs:[NSString stringWithFormat:@"window.plugins.jPushPlugin.receiveMessageIniOSCallback('%@')",jsonString]];
|
||||||
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user