From 4e687db4d394ec8086014d4c98c6068d539709c7 Mon Sep 17 00:00:00 2001 From: zhangqinghe Date: Fri, 16 Jan 2015 10:42:06 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=BA=86benginLogPageView?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 58 +++++++++++++++++++++++++++++------ src/ios/Plugins/JPushPlugin.m | 13 ++++++++ www/JPushPlugin.js | 8 +++++ 3 files changed, 69 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index d7e3551..dc105ca 100644 --- a/README.md +++ b/README.md @@ -21,19 +21,21 @@ cordova plugin add org.apache.cordova.device -3. 修改[your project]/plugins/android.json生成脚本的JPUSH_APPKEY字段 +3. 在cn.jpush.phonegap的JPushPlugin.java文件开始处 + + import your.package.name.R; + import cn.jpush.android.api.JPushInterface; + + + >温馨提示:如果使用eclipse来生成安装包,步骤4和5可省略。 + >直接在AndroidManifest.xml文件中修改JPUSH_APPKEY即可 + +4. 修改[your project]/plugins/android.json生成脚本的JPUSH_APPKEY字段 "xml": "", -4. 执行 cordova build android 使修改的`JPUSH_APPKEY`写入AndroidManifest.xml文件 - -> 温馨提示:如果使用eclipse来生成安装包,步骤2与步骤3可省略。直接在AndroidManifest.xml文件中修改JPUSH_APPKEY即可 - -5. 在cn.jpush.phonegap的JPushPlugin.java文件开始处,`import your.package.name.R;` - - - - +5. 执行 cordova build android 使修改的`JPUSH_APPKEY`写入AndroidManifest.xml文件 +6. 在js中调用函数 `window.plugins.jPushPlugin.init();` 初始化jpush sdk @@ -69,6 +71,7 @@                                                    UIRemoteNotificationTypeSound |                                                    UIRemoteNotificationTypeAlert)                                        categories:nil]; +   } #else     //categories 必须为nil   [APService registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge | @@ -281,3 +284,38 @@ eclipse中phonegap工程import之后出现:`Type CallbackContext cannot be resolved to a type` 解决方案:eclipse中右键单击工程名,Build Path->Config Build Path->Projects->选中 工程名称-CordovaLib->点击 add +### API说明 + +插件的API集中在JPushPlugin.js文件中,这个文件的位置如下 + +* android:[YOUR__ANDROID_PROJECT]/assets/www/plugins/cn.jpush.phonegap.JPushPlugin/www +* iOS:[YOUR_iOS_PROJEcT]/www/plugins/cn.jpush.phonegap.JPushPlugin/www + +这里只说明public的函数 + +#### API - startLogPageView,stopLogPageView,beginLogPageView + +本 API 用于“用户指定页面使用时长”的统计,并上报到服务器,在 Portal 上展示给开发者。页面统计集成正确,才能够获取正确的页面访问路径、访问深度(PV)的数据。 + +##### 接口定义 +JPushPlugin.prototype.startLogPageView = function(data) +JPushPlugin.prototype.stopLogPageView = function(data) + + + +#####使用平台 +iOS + +#####参数说明 +无参数 + +#####调用说明 + +#####返回值说明 +无 + +#####代码示例 +if(window.plugins.jPushPlugin.isPlatformIOS()){ + +} + diff --git a/src/ios/Plugins/JPushPlugin.m b/src/ios/Plugins/JPushPlugin.m index ba857f3..45c2a13 100644 --- a/src/ios/Plugins/JPushPlugin.m +++ b/src/ios/Plugins/JPushPlugin.m @@ -118,6 +118,19 @@ [APService stopLogPageView:pageName]; } +} +-(void)beginLogPageView:(CDVInvokedUrlCommand*)command{ + NSArray *arguments=command.arguments; + if (!arguments||[arguments count]<2) { + NSLog(@"beginLogPageView argument error"); + return ; + } + NSString * pageName=[arguments objectAtIndex:0]; + int duration=[[arguments objectAtIndex:0]intValue]; + if (pageName) { + [APService beginLogPageView:pageName duration:duration]; + } + } -(void)setBadge:(CDVInvokedUrlCommand*)command{ NSArray *argument=command.arguments; diff --git a/www/JPushPlugin.js b/www/JPushPlugin.js index d8ee343..3f17c24 100644 --- a/www/JPushPlugin.js +++ b/www/JPushPlugin.js @@ -1,6 +1,7 @@ var JPushPlugin = function(){ }; +//private plugin function JPushPlugin.prototype.isPlatformIOS = function(){ return device.platform == "iPhone" || device.platform == "iPad" || device.platform == "iPod touch" || device.platform == "iOS" @@ -15,6 +16,7 @@ JPushPlugin.prototype.call_native = function(name, args, callback){ ret = cordova.exec(callback,this.error_callback,'JPushPlugin',name,args); return ret; } +//public plugin function JPushPlugin.prototype.startLogPageView = function(data){ if(this.isPlatformIOS()){ @@ -28,6 +30,12 @@ JPushPlugin.prototype.stopLogPageView = function(data){ } } +JPushPlugin.prototype.beginLogPageView = function(pageName,duration){ + if(this.isPlatformIOS()){ + this.call_native( "beginLogPageView",[pageName,duration],null); + } +} + JPushPlugin.prototype.setTagsWithAlias = function(tags,alias){ try{ if(tags==null){