From 39b7987b2549983ff8c235914a86a97442303a77 Mon Sep 17 00:00:00 2001 From: zhangqinghe Date: Mon, 19 Jan 2015 16:37:44 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E5=AE=89=E8=A3=85=E6=96=87?= =?UTF-8?q?=E6=A1=A3=EF=BC=8C=E4=BD=BF=E5=AE=89=E8=A3=85=E8=BF=87=E7=A8=8B?= =?UTF-8?q?=E6=9B=B4=E7=AE=80=E6=B4=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 38 ++++++++++++++++-------------------- plugin.xml | 2 +- src/android/JPushPlugin.java | 29 +++++++++++++++------------ www/JPushPlugin.js | 7 ++++++- 4 files changed, 40 insertions(+), 36 deletions(-) diff --git a/README.md b/README.md index 7f069c2..89f52c6 100644 --- a/README.md +++ b/README.md @@ -6,37 +6,33 @@ 2. 添加平台 - cd Myproj :不进行这一步可能会出现[RangeError:Maximum call stack size exceeded] + cd Myproj :不进入项目会出现[RangeError:Maximum call stack size exceeded] cordova platform add android - + cordova platform add ios ### Android使用PhoneGap/Cordova CLI自动安装 -1. 使用 phonegap 或者 cordova cli 添加插件(建议在git客户端下使用,在windows 的cmd界面下 该命令提示git command line tool 不可用): - - cordova plugin add https://github.com/jpush/jpush-phonegap-plugin.git +1. 使用git命令将jpush phonegap插件下载的本地,将这个目录标记为`$JPUSH_PLUGIN_DIR` -2. 添加device插件,部分API需要根据平台进行调用,需添加org.apache.cordova.device插件 + git clone https://github.com/jpush/jpush-phonegap-plugin.git + +2. 将`$JPUSH_PLUGIN_DIR/plugin.xml`文件中的AppKey替换为在Portal上注册该应用的的Key,例如(9fed5bcb7b9b87413678c407) + + +3. 在`$JPUSH_PLUGIN_DIR/src/android/JPushPlugin.java` 文件`import your.package.name.R`替换为在Portal上注册该应用的包名,例如(com.thi.pushtest) + + +4. cordova cli 添加jpush phonegap插件和依赖的device插件: + + cordova plugin add $JPUSH_PLUGIN_DIR cordova plugin add org.apache.cordova.device -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": "", - -5. 执行 cordova build android 使修改的`JPUSH_APPKEY`写入AndroidManifest.xml文件 -6. 在js中调用函数 `window.plugins.jPushPlugin.init();` 初始化jpush sdk +5. 在js中调用函数,初始化jpush sdk + window.plugins.jPushPlugin.init(); + window.plugins.jPushPlugin.setDebugMode(true); ###IOS使用PhoneGap/Cordova CLI自动安装 diff --git a/plugin.xml b/plugin.xml index 0d88376..79a01e0 100644 --- a/plugin.xml +++ b/plugin.xml @@ -153,7 +153,7 @@ - + diff --git a/src/android/JPushPlugin.java b/src/android/JPushPlugin.java index a60ddc5..719fed9 100644 --- a/src/android/JPushPlugin.java +++ b/src/android/JPushPlugin.java @@ -19,11 +19,12 @@ import org.json.JSONException; import org.json.JSONObject; import java.util.Map.Entry; -//import com.your.package.name.R; +import your.package.name.R; import cn.jpush.android.api.BasicPushNotificationBuilder; import cn.jpush.android.api.CustomPushNotificationBuilder; import cn.jpush.android.api.JPushInterface; +import cn.jpush.android.data.JPushLocalNotification; import cn.jpush.android.api.TagAliasCallback; public class JPushPlugin extends CordovaPlugin { @@ -62,10 +63,11 @@ public class JPushPlugin extends CordovaPlugin { @Override public void initialize(CordovaInterface cordova, CordovaWebView webView) { super.initialize(cordova, webView); - JPushInterface.setDebugMode(true); - JPushInterface.init(cordova.getActivity().getApplicationContext()); + //JPushInterface.setDebugMode(true); + //JPushInterface.init(cordova.getActivity().getApplicationContext()); } + private static JSONObject notificationObject(String message, Map extras) { JSONObject data = new JSONObject(); @@ -162,16 +164,17 @@ public class JPushPlugin extends CordovaPlugin { } void setDebugMode(JSONArray data, CallbackContext callbackContext) { - String mode; + boolean mode; try { - mode = data.getString(0); - if (mode.equals("true")) { - JPushInterface.setDebugMode(true); - } else if (mode.equals("false")) { - JPushInterface.setDebugMode(false); - } else { - callbackContext.error("error mode"); - } + mode = data.getBoolean(0); + // if (mode.equals("true")) { + // JPushInterface.setDebugMode(true); + // } else if (mode.equals("false")) { + // JPushInterface.setDebugMode(false); + // } else { + // callbackContext.error("error mode"); + // } + JPushInterface.setDebugMode(mode); callbackContext.success(); } catch (JSONException e) { } @@ -209,7 +212,7 @@ public class JPushPlugin extends CordovaPlugin { callbackContext.error("error reading num json"); } if(num != -1){ - JPushInterface.setLatestNotifactionNumber(this.cordova.getActivity().getApplicationContext(), num); + JPushInterface.setLatestNotificationNumber(this.cordova.getActivity().getApplicationContext(), num); }else{ callbackContext.error("error num"); } diff --git a/www/JPushPlugin.js b/www/JPushPlugin.js index bc7d93a..9d672c8 100644 --- a/www/JPushPlugin.js +++ b/www/JPushPlugin.js @@ -198,7 +198,12 @@ JPushPlugin.prototype.resumePush = function(){ this.call_native("resumePush",data,null); } } - +JPushPlugin.prototype.setDebugMode = function(mode){ + if(device.platform == "Android") { + this.call_native("setDebugMode",[mode],null); + } +} +//setDebugMode JPushPlugin.prototype.clearAllNotification = function(){ if(device.platform == "Android") { data=[]