diff --git a/example/index.html b/example/index.html
index 9888c7f..cca460c 100644
--- a/example/index.html
+++ b/example/index.html
@@ -14,28 +14,98 @@
@@ -53,6 +123,12 @@
JPushPlugin Example
+
+
+
+
+
+
@@ -85,6 +161,10 @@
+
+
+
+
diff --git a/plugin.xml b/plugin.xml
index 66b3b56..187115a 100644
--- a/plugin.xml
+++ b/plugin.xml
@@ -41,8 +41,9 @@
-
-
+
+
+
diff --git a/src/ios/Plugins/JPushPlugin.h b/src/ios/Plugins/JPushPlugin.h
index b26f354..0abe0a9 100644
--- a/src/ios/Plugins/JPushPlugin.h
+++ b/src/ios/Plugins/JPushPlugin.h
@@ -16,4 +16,8 @@
-(void)setTags:(CDVInvokedUrlCommand*)command;
-(void)setAlias:(CDVInvokedUrlCommand*)command;
-(void)getRegistrationID:(CDVInvokedUrlCommand*)command;
+-(void)initNotifacationCenter:(CDVInvokedUrlCommand*)command;
+-(void)startLogPageView:(CDVInvokedUrlCommand*)command;
+-(void)stopLogPageView:(CDVInvokedUrlCommand*)command;
+
@end
diff --git a/src/ios/Plugins/JPushPlugin.m b/src/ios/Plugins/JPushPlugin.m
index b5424a0..5adb43a 100644
--- a/src/ios/Plugins/JPushPlugin.m
+++ b/src/ios/Plugins/JPushPlugin.m
@@ -10,7 +10,8 @@
#import "APService.h"
@implementation JPushPlugin
-
+
+
-(void)setTagsWithAlias:(CDVInvokedUrlCommand*)command{
NSArray *arguments=command.arguments;
@@ -55,11 +56,23 @@
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
}
+
+-(void)getRegistrationID:(CDVInvokedUrlCommand*)command{
+ NSString* registratonID = [APService registrionID];
+ dispatch_async(dispatch_get_main_queue(), ^{
+ //
+ NSString *script=[NSString stringWithFormat:@"cordova.fireDocumentEvent('registrationID','[%@]')",registratonID];
+ [self.commandDelegate evalJs:script];
+ [self writeJavascript:[NSString stringWithFormat:@"window.plugins.jPushPlugin.registrationCallback('%@')",registratonID]];
+ });
+
+}
+
-(void)tagsWithAliasCallback:(int)resultCode tags:(NSSet *)tags alias:(NSString *)alias{
- //NSLog(@"recode is %d tags is %@ alias %@",resultCode,tags,alias);
+ NSLog(@"recode is %d tags is %@ alias %@",resultCode,tags,alias);
NSDictionary *dict=[NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithInt:resultCode],@"resultCode",
tags==nil?[NSNull null]:[tags allObjects],@"resultTags",
@@ -68,12 +81,71 @@
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:dict options:0 error:&error];
NSString *jsonString = [[NSString alloc]initWithData:jsonData encoding:NSUTF8StringEncoding];
dispatch_async(dispatch_get_main_queue(), ^{
-
+ [self.commandDelegate evalJs:[NSString stringWithFormat:@"cordova.fireDocumentEvent('setTagsWithAlias','[%@]')",jsonString]];
+
[self writeJavascript:[NSString stringWithFormat:@"window.plugins.jPushPlugin.pushCallback('%@')",jsonString]];
});
}
--(void)getRegistrationID:(CDVInvokedUrlCommand*)command{
-
+- (void)networkDidSetup:(NSNotification *)notification {
+ [self.commandDelegate evalJs:[NSString stringWithFormat:@"cordova.fireDocumentEvent('networkDidSetup')"]];
+}
+
+- (void)networkDidClose:(NSNotification *)notification {
+ [self.commandDelegate evalJs:[NSString stringWithFormat:@"cordova.fireDocumentEvent('networkDidClose')"]];
+}
+
+- (void)networkDidRegister:(NSNotification *)notification {
+ [self.commandDelegate evalJs:[NSString stringWithFormat:@"cordova.fireDocumentEvent('networkDidRegister')"]];
+}
+
+- (void)networkDidLogin:(NSNotification *)notification {
+ [self.commandDelegate evalJs:[NSString stringWithFormat:@"cordova.fireDocumentEvent('networkDidLogin')"]];
+}
+
+-(void)initNotifacationCenter:(CDVInvokedUrlCommand*)command{
+
+ NSNotificationCenter *defaultCenter = [NSNotificationCenter defaultCenter];
+
+ [defaultCenter addObserver:self
+ selector:@selector(networkDidSetup:)
+ name:kAPNetworkDidSetupNotification
+ object:nil];
+ [defaultCenter addObserver:self
+ selector:@selector(networkDidClose:)
+ name:kAPNetworkDidCloseNotification
+ object:nil];
+ [defaultCenter addObserver:self
+ selector:@selector(networkDidRegister:)
+ name:kAPNetworkDidRegisterNotification
+ object:nil];
+ [defaultCenter addObserver:self
+ selector:@selector(networkDidLogin:)
+ name:kAPNetworkDidLoginNotification
+ object:nil];
+
+}
+-(void)startLogPageView:(CDVInvokedUrlCommand*)command{
+ NSArray *arguments=command.arguments;
+ if (!arguments||[arguments count]<1) {
+ NSLog(@"startLogPageView argument error");
+ return ;
+ }
+ NSString * pageName=[arguments objectAtIndex:0];
+ if (pageName) {
+ [APService startLogPageView:pageName];
+ }
+}
+-(void)stopLogPageView:(CDVInvokedUrlCommand*)command{
+ NSArray *arguments=command.arguments;
+ if (!arguments||[arguments count]<1) {
+ NSLog(@"stopLogPageView argument error");
+ return ;
+ }
+ NSString * pageName=[arguments objectAtIndex:0];
+ if (pageName) {
+ [APService stopLogPageView:pageName];
+ }
+
}
diff --git a/www/JPushPlugin.js b/www/JPushPlugin.js
index 4da3492..72f4219 100644
--- a/www/JPushPlugin.js
+++ b/www/JPushPlugin.js
@@ -1,4 +1,4 @@
-
+cordova.define("cn.jpush.phonegap.JPushPlugin.JPushPlugin", function(require, exports, module) {
var JPushPlugin = function(){
};
@@ -11,6 +11,67 @@ JPushPlugin.prototype.call_native = function ( name, args) {
args);
return ret;
}
+JPushPlugin.prototype.getRegistrationID = function () {
+
+ this.call_native( "getRegistrationID", null);
+
+}
+JPushPlugin.prototype.startLogPageView = function (data) {
+ if (data==null || typeof(data)=="undefined" || data==""){
+ console.log("argument is null");
+
+ }
+ else{
+ this.call_native( "startLogPageView", [data]);
+
+ }
+}
+JPushPlugin.prototype.stopLogPageView = function (data) {
+ if (data==null || typeof(data)=="undefined" || data==""){
+ console.log("argument is null");
+
+ }
+ else{
+ this.call_native( "stopLogPageView", [data]);
+
+ }
+}
+JPushPlugin.prototype.initNotificationCenter = function () {
+
+ this.call_native( "initNotifacationCenter", null);
+
+}
+JPushPlugin.prototype.parseEvent = function (data) {
+ try{
+ var parament=""
+ var count=1;
+ var start=false;
+ for(var i in data){
+
+ if(data[i]=='['){
+ if (count==1&&start==false) {
+ start=true;
+ continue;
+ }
+ count++;
+ }
+ if (data[i]==']') {
+ if(count==1)
+ {
+ break;
+ }
+ count--;
+ }
+
+ parament+=data[i]
+
+ }
+ return parament;
+ }
+ catch(exception){
+ alert(exception);
+ }
+}
JPushPlugin.prototype.setTagsWithAlias = function (tags,alias) {
@@ -52,12 +113,21 @@ JPushPlugin.prototype.pushCallback = function (data) {
var code = bToObj.resultCode;
var tags = bToObj.resultTags;
var alias = bToObj.resultAlias;
-
+ console.log("JPushPlugin:callBack--code is "+code+" tags is "+tags + " alias is "+alias);
}
catch(exception){
+
alert(exception);
}
}
+JPushPlugin.prototype.registrationCallback = function (data) {
+ try{
+ console.log("registrationCallback--registraionID is "+data);
+ }
+ catch(exception){
+ alert(exception);
+ }
+}
if(!window.plugins) {
window.plugins = {};
}
@@ -65,3 +135,5 @@ if(!window.plugins.jPushPlugin){
window.plugins.jPushPlugin = new JPushPlugin();
}
module.exports = new JPushPlugin();
+
+});