From 7545a948bda39b9017b4a042ada0c10d664a0845 Mon Sep 17 00:00:00 2001 From: zhangqinghe Date: Tue, 14 Apr 2015 14:47:57 +0800 Subject: [PATCH] demo add openNotification receiveNotification receiveMessage code --- example/index.html | 93 ++++++++++++++++++++++++----------- src/ios/Plugins/JPushPlugin.m | 3 ++ 2 files changed, 66 insertions(+), 30 deletions(-) diff --git a/example/index.html b/example/index.html index 9acfc84..9f0d715 100644 --- a/example/index.html +++ b/example/index.html @@ -13,7 +13,18 @@ var onDeviceReady = function(){ console.log("JPushPlugin:Device ready!") initiateUI(); - } + } + var onGetRegistradionID = function(data) { + try{ + console.log("JPushPlugin:registrationID is "+data) + + $("#registrationid").html(data); + } + catch(exception){ + console.log(exception); + } + } + var onTagsWithAlias = function(event){ try{ console.log("onTagsWithAlias"); @@ -29,8 +40,8 @@ var onOpenNotification = function(event){ try{ - var alert = event.aps.alert; - console.log("JPushPlugin:onPpenNotification key aps.alert:"+alert); + var alertContent = event.aps.alert; + alert("open Notificaiton:"+alertContent); } catch(exception){ console.log("JPushPlugin:onPpenNotification"+exception); @@ -38,51 +49,59 @@ } var onReceiveNotification = function(event){ 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){ console.log(exception) } } - - var onGetRegistradionID = function(data) { + var onReceiveMessage = function(event){ 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){ - console.log(exception); + console.log("JPushPlugin:onReceiveMessage"+exception); } } + var initiateUI = function(){ try{ window.plugins.jPushPlugin.init(); - window.plugins.jPushPlugin.setDebugMode(true); - window.plugins.jPushPlugin.getRegistrationID(onGetRegistradionID); - window.plugins.jPushPlugin.setApplicationIconBadgeNumber(5); -// var extras={"name":"json"}; -// window.plugins.jPushPlugin.addLocalNotification(1,"hh","ln",1111,1000*60,extras); -// window.plugins.jPushPlugin.removeLocalNotification(1111); -// window.plugins.jPushPlugin.clearLocalNotifications(); + window.plugins.jPushPlugin.getRegistrationID(onGetRegistradionID); + + if(JPushPlugin.prototype.isPlatformIOS()){ + window.plugins.jPushPlugin.setDebugModeFromIos(); + window.plugins.jPushPlugin.setApplicationIconBadgeNumber(0); + }else{ + window.plugins.jPushPlugin.setDebugMode(true); + } } catch(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) { try{ var tag1 = $("#tagText1").attr("value"); @@ -112,11 +131,14 @@ } }) } - document.addEventListener("jpush.receiveNotification", onReceiveNotification, false); document.addEventListener("jpush.setTagsWithAlias", onTagsWithAlias, false); document.addEventListener("deviceready", onDeviceReady, false); document.addEventListener("jpush.openNotification", onOpenNotification, false); + document.addEventListener("jpush.receiveNotification", onReceiveNotification, false); + document.addEventListener("jpush.receiveMessage", onReceiveMessage, false); + + //jpush.receiveMessage @@ -164,8 +186,19 @@
+
+
+ + +
+
+ + +
+ + diff --git a/src/ios/Plugins/JPushPlugin.m b/src/ios/Plugins/JPushPlugin.m index eb3681a..a48d283 100644 --- a/src/ios/Plugins/JPushPlugin.m +++ b/src/ios/Plugins/JPushPlugin.m @@ -296,8 +296,11 @@ static NSDictionary *_luanchOptions=nil; 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]]; + }); }