diff --git a/README.md b/README.md index 66d9d7e..2432dcb 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # JPush PhoneGap / Cordova Plugin [![Build Status](https://travis-ci.org/jpush/jpush-phonegap-plugin.svg?branch=master)](https://travis-ci.org/jpush/jpush-phonegap-plugin) -[![release](https://img.shields.io/badge/release-3.2.3-blue.svg)](https://github.com/jpush/jpush-phonegap-plugin/releases) +[![release](https://img.shields.io/badge/release-3.2.4-blue.svg)](https://github.com/jpush/jpush-phonegap-plugin/releases) [![platforms](https://img.shields.io/badge/platforms-iOS%7CAndroid-lightgrey.svg)](https://github.com/jpush/jpush-phonegap-plugin) [![weibo](https://img.shields.io/badge/weibo-JPush-blue.svg)](http://weibo.com/jpush?refer_flag=1001030101_&is_all=1) diff --git a/doc/Common_detail_api.md b/doc/Common_detail_api.md index 529b7f2..661e245 100644 --- a/doc/Common_detail_api.md +++ b/doc/Common_detail_api.md @@ -23,7 +23,9 @@ #### 接口定义 - window.plugins.jPushPlugin.init() +```js +window.JPush.init() +``` ### API - stopPush + Android 平台: @@ -43,7 +45,9 @@ #### 接口定义 - window.plugins.jPushPlugin.stopPush() +```js +window.JPush.stopPush() +``` ### API - resumePush @@ -59,7 +63,7 @@ #### 接口定义 - window.plugins.jPushPlugin.resumePush() + window.JPush.resumePush() ### API - isPushStopped @@ -73,37 +77,39 @@ #### 接口定义 - window.plugins.jPushPlugin.isPushStopped(callback) +```js +window.JPush.isPushStopped(callback) +``` #### 参数说明 -+ callback: 回调函数,用来通知 JPush 的推送服务是否开启。 +- callback: 回调函数,用来通知 JPush 的推送服务是否开启。 #### 代码示例 - window.plugins.jPushPlugin.isPushStopped(function (result) { - if (result == 0) { - // 开启 - } else { - // 关闭 - } - }) +```js +window.JPush.isPushStopped(function (result) { + if (result == 0) { + // 开启 + } else { + // 关闭 + } +}) +``` ## 开启 Debug 模式 ### API - setDebugMode 用于开启 Debug 模式,显示更多的日志信息。 -#### 接口定义 +#### 代码示例 - JPushPlugin.prototype.setDebugMode(isOpen) +```js +window.JPush.setDebugMode(true) +``` #### 参数说明 - isOpen: true,开启 Debug 模式;false,关闭 Debug 模式,不显示错误信息之外的日志信息。 -#### 代码示例 - - window.plugins.jPushPlugin.setDebugMode(true) - ## 获取 RegistrationID ### API - getRegistrationID @@ -117,7 +123,7 @@ JPush SDK 会以广播的形式发送 RegistrationID 到应用程序。 #### 接口定义 - JPushPlugin.prototype.getRegistrationID(callback) + window.JPush.getRegistrationID(callback) #### 返回值 @@ -125,14 +131,14 @@ JPush SDK 会以广播的形式发送 RegistrationID 到应用程序。 #### 代码示例 - window.plugins.jPushPlugin.getRegistrationID(function(data) { - console.log("JPushPlugin:registrationID is " + data) - }) +```js +window.JPush.getRegistrationID(function(rId) { + console.log("JPushPlugin:registrationID is " + rId) +}) +``` ## 设置别名与标签 -### API - setTagsWithAlias, setTags, setAlias - 提供几个相关 API 用来设置别名(alias)与标签(tags)。 这几个 API 可以在 App 里任何地方调用。 @@ -159,54 +165,200 @@ JPush SDK 会以广播的形式发送 RegistrationID 到应用程序。 举例: game, old_page, women。 -#### 接口定义 +> 以下方法的错误回调均包含 `sequence` 和 `code` 属性。其中 code 为错误码,具体定义可参考[官方文档](https://docs.jiguang.cn/jpush/client/Android/android_api/#_133)。 -```js -JPushPlugin.prototype.setTagsWithAlias(tags, alias, successCallback, errorCallback) -JPushPlugin.prototype.setTags(tags, successCallback, errorCallback) -JPushPlugin.prototype.setAlias(alias, successCallback, errorCallback) -``` +### setAlias -#### 参数说明 -* tags: - * 参数类型为数组。 - * nil 此次调用不设置此值。 - * 空集合表示取消之前的设置。 - * 每次调用至少设置一个 tag,覆盖之前的设置,不是新增。 - * 有效的标签组成:字母(区分大小写)、数字、下划线、汉字。 - * 限制:每个 tag 命名长度限制为 40 字节,最多支持设置 100 个 tag,但总长度不得超过1K字节(判断长度需采用 UTF-8 编码)。 - * 单个设备最多支持设置 100 个 tag,App 全局 tag 数量无限制。 -* alias: - * 参数类型为字符串。 - * nil 此次调用不设置此值。 - * 空字符串 ("")表示取消之前的设置。 - * 有效的别名组成:字母(区分大小写)、数字、下划线、汉字。 - * 限制:alias 命名长度限制为 40 字节(判断长度需采用 UTF-8 编码)。 +设置别名。注意这个接口是覆盖逻辑,而不是增量逻辑。即新的调用会覆盖之前的设置。 #### 代码示例 ```js -window.plugins.jPushPlugin.setTagsWithAlias([tag1, tag2], alias1, function () { - // success callback. -}, function (errorMsg) { - // errorMsg 格式为 'errorCode: error message'. -}) +window.JPush.setAlias({ sequence: 1, alias: 'your_alias' }, + (result) => { + var sequence = result.sequence + var alias = result.alias + }, (error) => { + var sequence = error.sequence + var errorCode = error.code + }) ``` -#### 错误码定义 +#### 参数说明 -|Code|描述 |详细解释 | -|----|:----------------------------------------|:--------| -|6001|无效的设置,tag / alias 不应参数都为 null。 | | -|6002|设置超时。 |建议重试。| -|6003|alias 字符串不合法。 |有效的别名、标签组成:字母(区分大小写)、数字、下划线、汉字。| -|6004|alias超长。 |最多 40个字节,中文 UTF-8 是 3 个字节。| -|6005|某一个 tag 字符串不合法。 |有效的别名、标签组成:字母(区分大小写)、数字、下划线、汉字。| -|6006|某一个 tag 超长。 |一个 tag 最多 40个字节,中文 UTF-8 是 3 个字节。| -|6007|tags 数量超出限制,最多 100 个。 |这是一台设备的限制,一个应用全局的标签数量无限制。| -|6008|tag / alias 超出总长度限制。 |总长度最多 1K 字节。| -|6011|10s内设置 tag 或 alias 大于 3 次。 |短时间内操作过于频繁。| +- sequence: number。用户自定义的操作序列号, 同操作结果一起返回,用来标识一次操作的唯一性。 +- alias: string + - 每次调用设置有效的别名将覆盖之前的设置。 + - 有效的别名组成:字母(区分大小写)、数字、下划线、汉字、特殊字符@!#$&*+=.|。 + - 限制:alias 命名长度限制为 40 字节(判断长度需采用 UTF-8 编码)。 +### deleteAlias + +删除别名。 + +#### 代码示例 + +```js +window.JPush.deleteAlias({ sequence: 1 }, + (result) => { + var sequence = result.sequence + }, (error) => { + var sequence = error.sequence + var errorCode = error.code + }) +``` + +#### 参数说明 + +- sequence: number。用户自定义的操作序列号, 同操作结果一起返回,用来标识一次操作的唯一性。 + +### getAlias + +查询别名。 + +#### 代码示例 + +```js +window.JPush.getAlias({ sequence: 1 }, + (result) => { + var sequence = result.sequence + var alias = result.alias + }, (error) => { + var sequence = error.sequence + var errorCode = error.code + }) +``` + +#### 参数说明 + +- sequence: number。用户自定义的操作序列号, 同操作结果一起返回,用来标识一次操作的唯一性。 + +### setTags + +设置标签。注意这个接口是覆盖逻辑,而不是增量逻辑。即新的调用会覆盖之前的设置。 + +#### 代码示例 + +```js +window.JPush.setTags({ sequence: 1, tags: ['tag1', 'tag2'] }, + (result) => { + var sequence = result.sequence + var tags = result.tags // 数组类型 + }, (error) => { + var sequence = error.sequence + var errorCode = error.code + }) +``` + +#### 参数说明 + +- sequence: number。用户自定义的操作序列号, 同操作结果一起返回,用来标识一次操作的唯一性。 +- tags: Array,标签数组。 + +### addTags + +新增标签。 + +#### 代码示例 + +```js +window.JPush.addTags({ sequence: 1, tags: ['tag1', 'tag2'] }, + (result) => { + var sequence = result.sequence + var tags = result.tags // 数组类型 + }, (error) => { + var sequence = error.sequence + var errorCode = error.code + }) +``` + +#### 参数说明 + +- sequence: number。用户自定义的操作序列号, 同操作结果一起返回,用来标识一次操作的唯一性。 +- tags: Array,标签数组。 + +### deleteTags + +删除指定标签。 + +#### 代码示例 + +```js +window.JPush.deleteTags({ sequence: 1, tags: ['tag1', 'tag2'] }, + (result) => { + var sequence = result.sequence + }, (error) => { + var sequence = error.sequence + var errorCode = error.code + }) +``` + +#### 参数说明 + +- sequence: number。用户自定义的操作序列号, 同操作结果一起返回,用来标识一次操作的唯一性。 +- tags: Array,标签数组。 + +### cleanTags + +清除所有标签。 + +#### 代码示例 + +```js +window.JPush.cleanTags({ sequence: 1 }, + (result) => { + var sequence = result.sequence + }, (error) => { + var sequence = error.sequence + var errorCode = error.code + }) +``` + +#### 参数说明 + +- sequence: number。用户自定义的操作序列号, 同操作结果一起返回,用来标识一次操作的唯一性。 + +### getAllTags + +获取当前绑定的所有标签。 + +#### 代码示例 + +```js +window.JPush.getAllTags({ sequence: 1 }, + (result) => { + var sequence = result.sequence + var tags = result.tags + }, (error) => { + var sequence = error.sequence + var errorCode = error.code + }) +``` + +#### 参数说明 + +- sequence: number。用户自定义的操作序列号, 同操作结果一起返回,用来标识一次操作的唯一性。 + +### checkTagBindState + +查询指定tag与当前用户绑定的状态。 + +#### 代码示例 + +```js +window.JPush.checkTagBindState({ sequence: 1, tag: 'tag1' }, + (result) => { + var sequence = result.sequence + }, (error) => { + var sequence = error.sequence + var errorCode = error.code + }) +``` + +#### 参数说明 + +- sequence: number。用户自定义的操作序列号, 同操作结果一起返回,用来标识一次操作的唯一性。 +- tag: string,待查询的 tag。 ## 获取点击通知内容 @@ -227,7 +379,7 @@ window.plugins.jPushPlugin.setTagsWithAlias([tag1, tag2], alias1, function () { } }, false) -> ps:点击通知后传递的 json object 保存在 window.plugins.jPushPlugin.openNotification,直接访问即可,字段示例,根据实际推送情况,可能略有差别,请注意。 +> ps:点击通知后传递的 json object 保存在 window.JPush.openNotification,直接访问即可,字段示例,根据实际推送情况,可能略有差别,请注意。 + Android: @@ -280,7 +432,7 @@ window.plugins.jPushPlugin.setTagsWithAlias([tag1, tag2], alias1, function () { }, false) -> ps:点击通知后传递的 json object 保存在 window.plugins.jPushPlugin.receiveNotification,直接访问即可,字段示例,根据实际推送情况,可能略有差别,请注意。 +> ps:点击通知后传递的 json object 保存在 window.JPush.receiveNotification,直接访问即可,字段示例,根据实际推送情况,可能略有差别,请注意。 + Android: @@ -334,7 +486,7 @@ window.plugins.jPushPlugin.setTagsWithAlias([tag1, tag2], alias1, function () { } }, false) -> ps:点击通知后传递的 json object 保存在 window.plugins.jPushPlugin.receiveMessage,直接访问即可,字段示例,根据实际推送情况,可能略有差别,请注意。 +> ps:点击通知后传递的 json object 保存在 window.JPush.receiveMessage,直接访问即可,字段示例,根据实际推送情况,可能略有差别,请注意。 + Android: @@ -371,7 +523,7 @@ window.plugins.jPushPlugin.setTagsWithAlias([tag1, tag2], alias1, function () { #### 代码示例 - window.plugins.jPushPlugin.getUserNotificationSettings(function(result) { + window.JPush.getUserNotificationSettings(function(result) { if(result == 0) { // 系统设置中已关闭应用推送。 } else if(result > 0) { diff --git a/example/index.html b/example/index.html index 6a9b7ac..869263a 100644 --- a/example/index.html +++ b/example/index.html @@ -1,201 +1,262 @@ - - + + - JPush Phonegap Simple Demo - - - - - + + + - - - + + + +
-
-
-
-
-
-

JPushPlugin Example

-
- -
- - -
-
- - - - - - - - - - - -
- -
- -
- -
- - - - - -
- -
-
-
- -
-
- - -
-
- - -
-
- - -
-
-
-
-
- +
+
+
+
+
+

JPushPlugin Example

+
+ +
+ + +
+
+ + + + + + + + + + + +
+ +
+ +
+ +
+ + + + + +
+ +
+
- +
+ + + +
+ +
+ + + +
+ +
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+
+
+ + + \ No newline at end of file diff --git a/package.json b/package.json index e93442b..bbc7c96 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "jpush-phonegap-plugin", - "version": "3.2.3", + "version": "3.2.4", "description": "JPush for cordova plugin", "cordova": { "id": "jpush-phonegap-plugin", diff --git a/plugin.xml b/plugin.xml index 8c605e6..0a4a6f0 100644 --- a/plugin.xml +++ b/plugin.xml @@ -2,7 +2,7 @@ + version="3.2.4"> JPush JPush for cordova plugin @@ -192,10 +192,11 @@ - + + diff --git a/src/android/JPushEventReceiver.java b/src/android/JPushEventReceiver.java new file mode 100644 index 0000000..d69349c --- /dev/null +++ b/src/android/JPushEventReceiver.java @@ -0,0 +1,156 @@ +package cn.jiguang.cordova.push; + +import android.content.Context; +import android.text.TextUtils; +import android.util.Log; + +import org.apache.cordova.CallbackContext; +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; + +import java.util.Set; + +import cn.jpush.android.api.JPushMessage; +import cn.jpush.android.service.JPushMessageReceiver; + + +public class JPushEventReceiver extends JPushMessageReceiver { + + private static final String TAG = JPushEventReceiver.class.getSimpleName(); + + @Override + public void onTagOperatorResult(Context context, JPushMessage jPushMessage) { + super.onTagOperatorResult(context, jPushMessage); + + JSONObject resultJson = new JSONObject(); + + int sequence = jPushMessage.getSequence(); + try { + resultJson.put("sequence", sequence); + } catch (JSONException e) { + e.printStackTrace(); + } + + CallbackContext callback = JPushPlugin.eventCallbackMap.get(sequence); + + if (callback == null) { + Log.i(TAG, "Unexpected error, callback is null!"); + return; + } + + if (jPushMessage.getErrorCode() == 0) { // success + Set tags = jPushMessage.getTags(); + JSONArray tagsJsonArr = new JSONArray(); + for (String tag : tags) { + tagsJsonArr.put(tag); + } + + try { + if (tagsJsonArr.length() != 0) { + resultJson.put("tags", tagsJsonArr); + } + } catch (JSONException e) { + e.printStackTrace(); + } + + callback.success(resultJson); + + } else { + try { + resultJson.put("code", jPushMessage.getErrorCode()); + } catch (JSONException e) { + e.printStackTrace(); + } + + callback.error(resultJson); + } + + JPushPlugin.eventCallbackMap.remove(sequence); + } + + @Override + public void onCheckTagOperatorResult(Context context, JPushMessage jPushMessage) { + super.onCheckTagOperatorResult(context, jPushMessage); + + JSONObject resultJson = new JSONObject(); + + int sequence = jPushMessage.getSequence(); + try { + resultJson.put("sequence", sequence); + } catch (JSONException e) { + e.printStackTrace(); + } + + CallbackContext callback = JPushPlugin.eventCallbackMap.get(sequence); + + if (callback == null) { + Log.i(TAG, "Unexpected error, callback is null!"); + return; + } + + if (jPushMessage.getErrorCode() == 0) { + try { + resultJson.put("tag", jPushMessage.getCheckTag()); + resultJson.put("isBind", jPushMessage.getTagCheckStateResult()); + } catch (JSONException e) { + e.printStackTrace(); + } + + } else { + try { + resultJson.put("code", jPushMessage.getErrorCode()); + } catch (JSONException e) { + e.printStackTrace(); + } + + callback.error(resultJson); + } + + JPushPlugin.eventCallbackMap.remove(sequence); + } + + @Override + public void onAliasOperatorResult(Context context, JPushMessage jPushMessage) { + super.onAliasOperatorResult(context, jPushMessage); + + JSONObject resultJson = new JSONObject(); + + int sequence = jPushMessage.getSequence(); + try { + resultJson.put("sequence", sequence); + } catch (JSONException e) { + e.printStackTrace(); + } + + CallbackContext callback = JPushPlugin.eventCallbackMap.get(sequence); + + if (callback == null) { + Log.i(TAG, "Unexpected error, callback is null!"); + return; + } + + if (jPushMessage.getErrorCode() == 0) { // success + try { + if (!TextUtils.isEmpty(jPushMessage.getAlias())) { + resultJson.put("alias", jPushMessage.getAlias()); + } + } catch (JSONException e) { + e.printStackTrace(); + } + + callback.success(resultJson); + + } else { + try { + resultJson.put("code", jPushMessage.getErrorCode()); + } catch (JSONException e) { + e.printStackTrace(); + } + + callback.error(resultJson); + } + + JPushPlugin.eventCallbackMap.remove(sequence); + } +} diff --git a/src/android/JPushPlugin.java b/src/android/JPushPlugin.java index 0decb2d..38ba9ff 100644 --- a/src/android/JPushPlugin.java +++ b/src/android/JPushPlugin.java @@ -35,53 +35,29 @@ import cn.jpush.android.api.BasicPushNotificationBuilder; import cn.jpush.android.api.JPushInterface; import cn.jpush.android.api.TagAliasCallback; import cn.jpush.android.data.JPushLocalNotification; +import cn.jpush.android.service.JPushMessageReceiver; public class JPushPlugin extends CordovaPlugin { - private final static List methodList = - Arrays.asList( - "addLocalNotification", - "areNotificationEnabled", - "clearAllNotification", - "clearLocalNotifications", - "clearNotificationById", - "getNotification", - "getRegistrationID", - "init", - "isPushStopped", - "onPause", - "onResume", - "requestPermission", - "removeLocalNotification", - "reportNotificationOpened", - "resumePush", - "setAlias", - "setBasicPushNotificationBuilder", - "setCustomPushNotificationBuilder", - "setDebugMode", - "setLatestNotificationNum", - "setPushTime", - "setTags", - "setTagsWithAlias", - "setSilenceTime", - "setStatisticsOpen", - "stopPush" - ); private ExecutorService threadPool = Executors.newFixedThreadPool(1); + + private Context mContext; + private static JPushPlugin instance; private static Activity cordovaActivity; private static String TAG = "JPushPlugin"; - private static boolean shouldCacheMsg = false; private static boolean isStatisticsOpened = false; // 是否开启统计分析功能 - public static String notificationTitle; - public static String notificationAlert; - public static Map notificationExtras = new HashMap(); + static String notificationTitle; + static String notificationAlert; + static Map notificationExtras = new HashMap(); - public static String openNotificationTitle; - public static String openNotificationAlert; - public static Map openNotificationExtras = new HashMap(); + static String openNotificationTitle; + static String openNotificationAlert; + static Map openNotificationExtras = new HashMap(); + + static Map eventCallbackMap = new HashMap(); public JPushPlugin() { instance = this; @@ -89,10 +65,10 @@ public class JPushPlugin extends CordovaPlugin { @Override public void initialize(CordovaInterface cordova, CordovaWebView webView) { - Log.i(TAG, "JPush initialize."); - super.initialize(cordova, webView); - JPushInterface.init(cordova.getActivity().getApplicationContext()); + mContext = cordova.getActivity().getApplicationContext(); + + JPushInterface.init(mContext); cordovaActivity = cordova.getActivity(); @@ -110,17 +86,12 @@ public class JPushPlugin extends CordovaPlugin { } public void onPause(boolean multitasking) { - Log.i(TAG, "---------------- onPause"); - shouldCacheMsg = true; if (isStatisticsOpened && multitasking) { JPushInterface.onPause(this.cordova.getActivity()); } } public void onResume(boolean multitasking) { - shouldCacheMsg = false; - Log.i(TAG, "---------------- onResume" + "-" + openNotificationAlert - + "-" + notificationAlert); if (isStatisticsOpened && multitasking) { JPushInterface.onResume(this.cordova.getActivity()); } @@ -142,15 +113,14 @@ public class JPushPlugin extends CordovaPlugin { instance = null; } - private static JSONObject getMessageObject(String message, - Map extras) { + private static JSONObject getMessageObject(String message, Map extras) { JSONObject data = new JSONObject(); try { data.put("message", message); JSONObject jExtras = new JSONObject(); for (Entry entry : extras.entrySet()) { if (entry.getKey().equals("cn.jpush.android.EXTRA")) { - JSONObject jo = null; + JSONObject jo; if (TextUtils.isEmpty((String) entry.getValue())) { jo = new JSONObject(); } else { @@ -176,8 +146,7 @@ public class JPushPlugin extends CordovaPlugin { return data; } - private static JSONObject getNotificationObject(String title, - String alert, Map extras) { + private static JSONObject getNotificationObject(String title, String alert, Map extras) { JSONObject data = new JSONObject(); try { data.put("title", title); @@ -226,8 +195,7 @@ public class JPushPlugin extends CordovaPlugin { }); } - static void transmitNotificationOpen(String title, String alert, - Map extras) { + static void transmitNotificationOpen(String title, String alert, Map extras) { if (instance == null) { return; } @@ -244,8 +212,7 @@ public class JPushPlugin extends CordovaPlugin { JPushPlugin.openNotificationAlert = null; } - static void transmitNotificationReceive(String title, String alert, - Map extras) { + static void transmitNotificationReceive(String title, String alert, Map extras) { if (instance == null) { return; } @@ -285,9 +252,6 @@ public class JPushPlugin extends CordovaPlugin { @Override public boolean execute(final String action, final JSONArray data, final CallbackContext callbackContext) throws JSONException { - if (!methodList.contains(action)) { - return false; - } threadPool.execute(new Runnable() { @Override public void run() { @@ -304,7 +268,7 @@ public class JPushPlugin extends CordovaPlugin { } void init(JSONArray data, CallbackContext callbackContext) { - JPushInterface.init(this.cordova.getActivity().getApplicationContext()); + JPushInterface.init(mContext); } void setDebugMode(JSONArray data, CallbackContext callbackContext) { @@ -319,18 +283,17 @@ public class JPushPlugin extends CordovaPlugin { } void stopPush(JSONArray data, CallbackContext callbackContext) { - JPushInterface.stopPush(this.cordova.getActivity().getApplicationContext()); + JPushInterface.stopPush(mContext); callbackContext.success(); } void resumePush(JSONArray data, CallbackContext callbackContext) { - JPushInterface.resumePush(this.cordova.getActivity().getApplicationContext()); + JPushInterface.resumePush(mContext); callbackContext.success(); } void isPushStopped(JSONArray data, CallbackContext callbackContext) { - boolean isStopped = JPushInterface.isPushStopped( - this.cordova.getActivity().getApplicationContext()); + boolean isStopped = JPushInterface.isPushStopped(mContext); if (isStopped) { callbackContext.success(1); } else { @@ -358,7 +321,7 @@ public class JPushPlugin extends CordovaPlugin { } if (num != -1) { JPushInterface.setLatestNotificationNumber( - this.cordova.getActivity().getApplicationContext(), num); + mContext, num); } else { callbackContext.error("error num"); } @@ -384,13 +347,13 @@ public class JPushPlugin extends CordovaPlugin { } catch (JSONException e) { callbackContext.error("error reading hour json"); } - Context context = this.cordova.getActivity().getApplicationContext(); + Context context = mContext; JPushInterface.setPushTime(context, days, startHour, endHour); callbackContext.success(); } void getRegistrationID(JSONArray data, CallbackContext callbackContext) { - Context context = this.cordova.getActivity().getApplicationContext(); + Context context = mContext; String regID = JPushInterface.getRegistrationID(context); callbackContext.success(regID); } @@ -413,31 +376,167 @@ public class JPushPlugin extends CordovaPlugin { } } - void setTags(JSONArray data, CallbackContext callbackContext) { + void setAlias(JSONArray data, CallbackContext callbackContext) { + int sequence = -1; + String alias = null; + try { - HashSet tags = new HashSet(); - for (int i = 0; i < data.length(); i++) { - tags.add(data.getString(i)); - } - JPushInterface.setTags(this.cordova.getActivity().getApplicationContext(), - tags, mTagWithAliasCallback); - callbackContext.success(); + JSONObject params = data.getJSONObject(0); + sequence = params.getInt("sequence"); + alias = params.getString("alias"); } catch (JSONException e) { e.printStackTrace(); - callbackContext.error("Error reading tags JSON"); + callbackContext.error("Parameters error."); } + + JPushInterface.setAlias(mContext, sequence, alias); + eventCallbackMap.put(sequence, callbackContext); } - void setAlias(JSONArray data, CallbackContext callbackContext) { + void deleteAlias(JSONArray data, CallbackContext callbackContext) { + int sequence = -1; + try { - String alias = data.getString(0); - JPushInterface.setAlias(this.cordova.getActivity().getApplicationContext(), - alias, mTagWithAliasCallback); - callbackContext.success(); + JSONObject params = data.getJSONObject(0); + sequence = params.getInt("sequence"); } catch (JSONException e) { e.printStackTrace(); - callbackContext.error("Error reading alias JSON"); + callbackContext.error("Parameters error."); } + + JPushInterface.deleteAlias(mContext, sequence); + eventCallbackMap.put(sequence, callbackContext); + } + + void getAlias(JSONArray data, CallbackContext callbackContext) { + int sequence = -1; + + try { + JSONObject params = data.getJSONObject(0); + sequence = params.getInt("sequence"); + } catch (JSONException e) { + e.printStackTrace(); + callbackContext.error("Parameters error."); + } + + JPushInterface.getAlias(mContext, sequence); + eventCallbackMap.put(sequence, callbackContext); + } + + void setTags(JSONArray data, CallbackContext callbackContext) { + int sequence = -1; + Set tags = new HashSet(); + + try { + JSONObject params = data.getJSONObject(0); + sequence = params.getInt("sequence"); + + JSONArray tagsArr = params.getJSONArray("tags"); + for (int i = 0; i < tagsArr.length(); i++) { + tags.add(tagsArr.getString(i)); + } + + } catch (JSONException e) { + e.printStackTrace(); + callbackContext.error("Parameters error."); + } + + JPushInterface.setTags(mContext, sequence, tags); + eventCallbackMap.put(sequence, callbackContext); + } + + void addTags(JSONArray data, CallbackContext callbackContext) { + int sequence = -1; + Set tags = new HashSet(); + + try { + JSONObject params = data.getJSONObject(0); + sequence = params.getInt("sequence"); + + JSONArray tagsArr = params.getJSONArray("tags"); + for (int i = 0; i < tagsArr.length(); i++) { + tags.add(tagsArr.getString(i)); + } + + } catch (JSONException e) { + e.printStackTrace(); + callbackContext.error("Parameters error."); + } + + JPushInterface.addTags(mContext, sequence, tags); + eventCallbackMap.put(sequence, callbackContext); + } + + void deleteTags(JSONArray data, CallbackContext callbackContext) { + int sequence = -1; + Set tags = new HashSet(); + + try { + JSONObject params = data.getJSONObject(0); + sequence = params.getInt("sequence"); + + JSONArray tagsArr = params.getJSONArray("tags"); + for (int i = 0; i < tagsArr.length(); i++) { + tags.add(tagsArr.getString(i)); + } + + } catch (JSONException e) { + e.printStackTrace(); + callbackContext.error("Parameters error."); + } + + JPushInterface.deleteTags(mContext, sequence, tags); + eventCallbackMap.put(sequence, callbackContext); + } + + void cleanTags(JSONArray data, CallbackContext callbackContext) { + int sequence = -1; + + try { + JSONObject params = data.getJSONObject(0); + sequence = params.getInt("sequence"); + + } catch (JSONException e) { + e.printStackTrace(); + callbackContext.error("Parameters error."); + } + + JPushInterface.cleanTags(mContext, sequence); + eventCallbackMap.put(sequence, callbackContext); + } + + void getAllTags(JSONArray data, CallbackContext callbackContext) { + int sequence = -1; + + try { + JSONObject params = data.getJSONObject(0); + sequence = params.getInt("sequence"); + + } catch (JSONException e) { + e.printStackTrace(); + callbackContext.error("Parameters error."); + } + + JPushInterface.getAllTags(mContext, sequence); + eventCallbackMap.put(sequence, callbackContext); + } + + void checkTagBindState(JSONArray data, CallbackContext callbackContext) { + int sequence = -1; + String tag = null; + + try { + JSONObject params = data.getJSONObject(0); + sequence = params.getInt("sequence"); + tag = params.getString("tag"); + + } catch (JSONException e) { + e.printStackTrace(); + callbackContext.error("Parameters error."); + } + + JPushInterface.checkTagBindState(mContext, sequence, tag); + eventCallbackMap.put(sequence, callbackContext); } void setTagsWithAlias(JSONArray data, CallbackContext callbackContext) { @@ -449,7 +548,7 @@ public class JPushPlugin extends CordovaPlugin { for (int i = 0; i < tagsArray.length(); i++) { tags.add(tagsArray.getString(i)); } - JPushInterface.setAliasAndTags(this.cordova.getActivity().getApplicationContext(), + JPushInterface.setAliasAndTags(mContext, alias, tags, mTagWithAliasCallback); callbackContext.success(); } catch (JSONException e) { @@ -513,8 +612,7 @@ public class JPushPlugin extends CordovaPlugin { } } - void addLocalNotification(JSONArray data, CallbackContext callbackContext) - throws JSONException { + void addLocalNotification(JSONArray data, CallbackContext callbackContext) throws JSONException { int builderId = data.getInt(0); String content = data.getString(1); String title = data.getString(2); @@ -537,8 +635,7 @@ public class JPushPlugin extends CordovaPlugin { JPushInterface.addLocalNotification(this.cordova.getActivity(), ln); } - void removeLocalNotification(JSONArray data, CallbackContext callbackContext) - throws JSONException { + void removeLocalNotification(JSONArray data, CallbackContext callbackContext) throws JSONException { int notificationID = data.getInt(0); JPushInterface.removeLocalNotification(this.cordova.getActivity(), notificationID); } @@ -634,7 +731,7 @@ public class JPushPlugin extends CordovaPlugin { String pkg = context.getPackageName(); int uid = appInfo.uid; - Class appOpsClazz = null; + Class appOpsClazz; try { appOpsClazz = Class.forName(AppOpsManager.class.getName()); diff --git a/src/android/libs/jpush-android-3.0.8.jar b/src/android/libs/jpush-android-3.0.8.jar new file mode 100755 index 0000000..b72455e Binary files /dev/null and b/src/android/libs/jpush-android-3.0.8.jar differ diff --git a/src/android/libs/jpush-android_v3.0.6.jar b/src/android/libs/jpush-android_v3.0.6.jar deleted file mode 100644 index ef6e96f..0000000 Binary files a/src/android/libs/jpush-android_v3.0.6.jar and /dev/null differ diff --git a/src/ios/Plugins/JPushPlugin.h b/src/ios/Plugins/JPushPlugin.h index daf08b2..7c7da19 100644 --- a/src/ios/Plugins/JPushPlugin.h +++ b/src/ios/Plugins/JPushPlugin.h @@ -18,8 +18,17 @@ //以下为js中可调用接口 //设置标签、别名 -(void)setTagsWithAlias:(CDVInvokedUrlCommand*)command; + -(void)setTags:(CDVInvokedUrlCommand*)command; +-(void)addTags:(CDVInvokedUrlCommand*)command; +-(void)deleteTags:(CDVInvokedUrlCommand*)command; +-(void)cleanTags:(CDVInvokedUrlCommand*)command; +-(void)getAllTags:(CDVInvokedUrlCommand*)command; +-(void)checkTagBindState:(CDVInvokedUrlCommand*)command; + -(void)setAlias:(CDVInvokedUrlCommand*)command; +-(void)deleteAlias:(CDVInvokedUrlCommand*)command; +-(void)getAlias:(CDVInvokedUrlCommand*)command; //获取 RegistrationID -(void)getRegistrationID:(CDVInvokedUrlCommand*)command; diff --git a/src/ios/Plugins/JPushPlugin.m b/src/ios/Plugins/JPushPlugin.m index 6ca27e2..5281292 100644 --- a/src/ios/Plugins/JPushPlugin.m +++ b/src/ios/Plugins/JPushPlugin.m @@ -1,12 +1,3 @@ - -// -// PushTalkPlugin.m -// PushTalk -// -// Created by zhangqinghe on 13-12-13. -// -// - #import "JPushPlugin.h" #import "JPUSHService.h" #import @@ -113,34 +104,210 @@ }]; } --(void)setTags:(CDVInvokedUrlCommand*)command{ - NSArray *tags = command.arguments; +-(void)setTags:(CDVInvokedUrlCommand*)command { + NSDictionary* params = [command.arguments objectAtIndex:0]; + NSNumber* sequence = params[@"sequence"]; + NSArray* tags = params[@"tags"]; + [JPUSHService setTags:[NSSet setWithArray:tags] - alias:nil - fetchCompletionHandle:^(int iResCode, NSSet *iTags, NSString *iAlias) { - CDVPluginResult *result; - if (iResCode == 0) { - result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:nil]; - } else { - result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:nil]; - } - [self.commandDelegate sendPluginResult:result callbackId:command.callbackId]; - }]; + completion:^(NSInteger iResCode, NSSet *iTags, NSInteger seq) { + NSMutableDictionary* dic = [[NSMutableDictionary alloc] init]; + [dic setObject:sequence forKey:@"sequence"]; + + CDVPluginResult* result; + + if (iResCode == 0) { + [dic setObject:[iTags allObjects] forKey:@"tags"]; + result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:dic]; + } else { + [dic setValue:[NSNumber numberWithUnsignedInteger:iResCode] forKey:@"code"]; + result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsDictionary:dic]; + } + + [self.commandDelegate sendPluginResult:result callbackId:command.callbackId]; + } seq:[sequence integerValue]]; } --(void)setAlias:(CDVInvokedUrlCommand*)command{ - NSString *alias = [command argumentAtIndex:0]; - [JPUSHService setTags:nil - alias:alias - fetchCompletionHandle:^(int iResCode, NSSet *iTags, NSString *iAlias) { - CDVPluginResult *result; +-(void)addTags:(CDVInvokedUrlCommand *)command { + NSDictionary* params = [command.arguments objectAtIndex:0]; + NSNumber* sequence = params[@"sequence"]; + NSArray* tags = params[@"tags"]; + + [JPUSHService addTags:[NSSet setWithArray:tags] + completion:^(NSInteger iResCode, NSSet *iTags, NSInteger seq) { + NSMutableDictionary* dic = [[NSMutableDictionary alloc] init]; + [dic setObject:sequence forKey:@"sequence"]; + + CDVPluginResult* result; + + if (iResCode == 0) { + [dic setObject:[iTags allObjects] forKey:@"tags"]; + result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:dic]; + } else { + [dic setValue:[NSNumber numberWithUnsignedInteger:iResCode] forKey:@"code"]; + result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsDictionary:dic]; + } + + [self.commandDelegate sendPluginResult:result callbackId:command.callbackId]; + } seq:[sequence integerValue]]; +} + +-(void)deleteTags:(CDVInvokedUrlCommand *)command { + NSDictionary* params = [command.arguments objectAtIndex:0]; + NSNumber* sequence = params[@"sequence"]; + NSArray* tags = params[@"tags"]; + + [JPUSHService deleteTags:[NSSet setWithArray:tags] + completion:^(NSInteger iResCode, NSSet *iTags, NSInteger seq) { + NSMutableDictionary* dic = [[NSMutableDictionary alloc] init]; + [dic setObject:sequence forKey:@"sequence"]; + + CDVPluginResult* result; + + if (iResCode == 0) { + [dic setObject:[iTags allObjects] forKey:@"tags"]; + result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:dic]; + } else { + [dic setValue:[NSNumber numberWithUnsignedInteger:iResCode] forKey:@"code"]; + result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsDictionary:dic]; + } + + [self.commandDelegate sendPluginResult:result callbackId:command.callbackId]; + } seq:[sequence integerValue]]; +} + +-(void)cleanTags:(CDVInvokedUrlCommand *)command { + NSDictionary* params = [command.arguments objectAtIndex:0]; + NSNumber* sequence = params[@"sequence"]; + + [JPUSHService cleanTags:^(NSInteger iResCode, NSSet *iTags, NSInteger seq) { + NSMutableDictionary* dic = [[NSMutableDictionary alloc] init]; + [dic setObject:sequence forKey:@"sequence"]; + + CDVPluginResult* result; + if (iResCode == 0) { - result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:nil]; + result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:dic]; } else { - result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:nil]; + [dic setValue:[NSNumber numberWithUnsignedInteger:iResCode] forKey:@"code"]; + result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsDictionary:dic]; } + [self.commandDelegate sendPluginResult:result callbackId:command.callbackId]; - }]; + } seq:[sequence integerValue]]; +} + +-(void)getAllTags:(CDVInvokedUrlCommand *)command { + NSDictionary* params = [command.arguments objectAtIndex:0]; + NSNumber* sequence = params[@"sequence"]; + + [JPUSHService getAllTags:^(NSInteger iResCode, NSSet *iTags, NSInteger seq) { + NSMutableDictionary* dic = [[NSMutableDictionary alloc] init]; + [dic setObject:sequence forKey:@"sequence"]; + + CDVPluginResult* result; + + if (iResCode == 0) { + [dic setObject:[iTags allObjects] forKey:@"tags"]; + result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:dic]; + } else { + [dic setValue:[NSNumber numberWithUnsignedInteger:iResCode] forKey:@"code"]; + result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsDictionary:dic]; + } + + [self.commandDelegate sendPluginResult:result callbackId:command.callbackId]; + } seq:[sequence integerValue]]; +} + +-(void)checkTagBindState:(CDVInvokedUrlCommand *)command { + NSDictionary* params = [command.arguments objectAtIndex:0]; + NSNumber* sequence = params[@"sequence"]; + NSString* tag = params[@"tag"]; + + [JPUSHService validTag:tag completion:^(NSInteger iResCode, NSSet *iTags, NSInteger seq, BOOL isBind) { + NSMutableDictionary* dic = [[NSMutableDictionary alloc] init]; + [dic setObject:sequence forKey:@"sequence"]; + + CDVPluginResult* result; + + if (iResCode == 0) { + [dic setObject:[iTags allObjects] forKey:@"tags"]; + [dic setObject:[NSNumber numberWithBool:isBind] forKey:@"isBind"]; + result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:dic]; + } else { + [dic setValue:[NSNumber numberWithUnsignedInteger:iResCode] forKey:@"code"]; + result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsDictionary:dic]; + } + + [self.commandDelegate sendPluginResult:result callbackId:command.callbackId]; + } seq:[sequence integerValue]]; +} + +-(void)setAlias:(CDVInvokedUrlCommand*)command { + NSDictionary* params = [command.arguments objectAtIndex:0]; + NSNumber* sequence = params[@"sequence"]; + NSString* alias = params[@"alias"]; + + [JPUSHService setAlias:alias completion:^(NSInteger iResCode, NSString *iAlias, NSInteger seq) { + NSMutableDictionary* dic = [[NSMutableDictionary alloc] init]; + [dic setObject:sequence forKey:@"sequence"]; + + CDVPluginResult* result; + + if (iResCode == 0) { + [dic setObject:iAlias forKey:@"alias"]; + result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:dic]; + + } else { + [dic setValue:[NSNumber numberWithUnsignedInteger:iResCode] forKey:@"code"]; + result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsDictionary:dic]; + } + + [self.commandDelegate sendPluginResult:result callbackId:command.callbackId]; + } seq:[sequence integerValue]]; +} + +-(void)deleteAlias:(CDVInvokedUrlCommand*)command { + NSDictionary* params = [command.arguments objectAtIndex:0]; + NSNumber* sequence = params[@"sequence"]; + + [JPUSHService deleteAlias:^(NSInteger iResCode, NSString *iAlias, NSInteger seq) { + NSMutableDictionary* dic = [[NSMutableDictionary alloc] init]; + [dic setObject:sequence forKey:@"sequence"]; + + CDVPluginResult* result; + + if (iResCode == 0) { + result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:dic]; + } else { + [dic setValue:[NSNumber numberWithUnsignedInteger:iResCode] forKey:@"code"]; + result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsDictionary:dic]; + } + + [self.commandDelegate sendPluginResult:result callbackId:command.callbackId]; + } seq:[sequence integerValue]]; +} + +-(void)getAlias:(CDVInvokedUrlCommand*)command { + NSDictionary* params = [command.arguments objectAtIndex:0]; + NSNumber* sequence = params[@"sequence"]; + + [JPUSHService getAlias:^(NSInteger iResCode, NSString *iAlias, NSInteger seq) { + NSMutableDictionary* dic = [[NSMutableDictionary alloc] init]; + [dic setObject:sequence forKey:@"sequence"]; + + CDVPluginResult* result; + + if (iResCode == 0) { + [dic setObject:iAlias forKey:@"alias"]; + result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:dic]; + } else { + [dic setValue:[NSNumber numberWithUnsignedInteger:iResCode] forKey:@"code"]; + result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsDictionary:dic]; + } + + [self.commandDelegate sendPluginResult:result callbackId:command.callbackId]; + } seq:[sequence integerValue]]; } -(void)getRegistrationID:(CDVInvokedUrlCommand*)command{ @@ -346,16 +513,7 @@ [self.commandDelegate sendPluginResult:result callbackId:command.callbackId]; } -#pragma mark 设置标签及别名回调 --(void)tagsWithAliasCallback:(int)resultCode tags:(NSSet *)tags alias:(NSString *)alias { - if (resultCode == 0) { // Success - - } else { - - } -} - -- (void)networkDidReceiveMessage:(NSNotification *)notification { +-(void)networkDidReceiveMessage:(NSNotification *)notification { if (notification && notification.userInfo) { [JPushPlugin fireDocumentEvent:JPushDocumentEvent_ReceiveMessage jsString:[notification.userInfo toJsonString]]; diff --git a/src/ios/lib/JPUSHService.h b/src/ios/lib/JPUSHService.h old mode 100644 new mode 100755 index 8912735..37deb15 --- a/src/ios/lib/JPUSHService.h +++ b/src/ios/lib/JPUSHService.h @@ -9,7 +9,7 @@ * Copyright (c) 2011 ~ 2017 Shenzhen HXHG. All rights reserved. */ -#define JPUSH_VERSION_NUMBER 3.0.5 +#define JPUSH_VERSION_NUMBER 3.0.6 #import @@ -22,6 +22,10 @@ @class UNNotification; @protocol JPUSHRegisterDelegate; +typedef void (^JPUSHTagsOperationCompletion)(NSInteger iResCode, NSSet *iTags, NSInteger seq); +typedef void (^JPUSHTagValidOperationCompletion)(NSInteger iResCode, NSSet *iTags, NSInteger seq, BOOL isBind); +typedef void (^JPUSHAliasOperationCompletion)(NSInteger iResCode, NSString *iAlias, NSInteger seq); + extern NSString *const kJPFNetworkIsConnectingNotification; // 正在连接中 extern NSString *const kJPFNetworkDidSetupNotification; // 建立连接 extern NSString *const kJPFNetworkDidCloseNotification; // 关闭连接 @@ -137,6 +141,7 @@ typedef NS_OPTIONS(NSUInteger, JPAuthorizationOptions) { * @param appKey 一个JPush 应用必须的,唯一的标识. 请参考 JPush 相关说明文档来获取这个标识. * @param channel 发布渠道. 可选. * @param isProduction 是否生产环境. 如果为开发状态,设置为 NO; 如果为生产状态,应改为 YES. + * App 证书环境取决于profile provision的配置,此处建议与证书环境保持一致. * @param advertisingIdentifier 广告标识符(IDFA) 如果不需要使用IDFA,传nil. * * @discussion 提供SDK启动必须的参数, 来启动 SDK. @@ -186,41 +191,102 @@ typedef NS_OPTIONS(NSUInteger, JPAuthorizationOptions) { */ + (void)handleRemoteNotification:(NSDictionary *)remoteInfo; - -///---------------------------------------------------- -/// @name Tag alias setting 设置别名与标签 -///---------------------------------------------------- - /*! - * 下面的接口是可选的 - * 设置标签和(或)别名(若参数为nil,则忽略;若是空对象,则清空;详情请参考文档:https://docs.jiguang.cn/jpush/client/iOS/ios_api/) - * setTags:alias:fetchCompletionHandle:是新的设置标签别名的方法,不再需要显示声明回调函数,只需要在block里面处理设置结果即可. - * WARN: 使用block时需要注意循环引用问题 + * Tags操作接口 + * 支持增加/覆盖/删除/清空/查询操作 + * 详情请参考文档:https://docs.jiguang.cn/jpush/client/iOS/ios_api/) */ -+ (void) setTags:(NSSet *)tags - alias:(NSString *)alias -callbackSelector:(SEL)cbSelector - target:(id)theTarget __attribute__((deprecated("JPush 2.1.1 版本已过期"))); -+ (void) setTags:(NSSet *)tags - alias:(NSString *)alias -callbackSelector:(SEL)cbSelector - object:(id)theTarget; +/** + 增加tags -+ (void) setTags:(NSSet *)tags -callbackSelector:(SEL)cbSelector - object:(id)theTarget; + @param tags 需要增加的tags集合 + @param completion 响应回调 + @param seq 请求序列号 + */ ++ (void)addTags:(NSSet *)tags + completion:(JPUSHTagsOperationCompletion)completion + seq:(NSInteger)seq; -+ (void)setTags:(NSSet *)tags - alias:(NSString *)alias - fetchCompletionHandle:(void (^)(int iResCode, NSSet *iTags, NSString *iAlias))completionHandler; +/** + 覆盖tags + 调用该接口会覆盖用户所有的tags -+ (void) setTags:(NSSet *)tags -aliasInbackground:(NSString *)alias; + @param tags 需要设置的tags集合 + @param completion 响应回调 + @param seq 请求序列号 + */ ++ (void)setTags:(NSSet *)tags + completion:(JPUSHTagsOperationCompletion)completion + seq:(NSInteger)seq; +/** + 删除指定tags + + @param tags 需要删除的tags集合 + @param completion 响应回调 + @param seq 请求序列号 + */ ++ (void)deleteTags:(NSSet *)tags + completion:(JPUSHTagsOperationCompletion)completion + seq:(NSInteger)seq; + +/** + 清空所有tags + @param completion 响应回调 + @param seq 请求序列号 + */ ++ (void)cleanTags:(JPUSHTagsOperationCompletion)completion + seq:(NSInteger)seq; + +/** + 查询全部tags + + @param completion 响应回调,请在回调中获取查询结果 + @param seq 请求序列号 + */ ++ (void)getAllTags:(JPUSHTagsOperationCompletion)completion + seq:(NSInteger)seq; + +/** + 验证tag是否绑定 + + @param completion 响应回调,回调中查看是否绑定 + @param seq 请求序列号 + */ ++ (void)validTag:(NSString *)tag + completion:(JPUSHTagValidOperationCompletion)completion + seq:(NSInteger)seq; + +/** + 设置Alias + + @param alias 需要设置的alias + @param completion 响应回调 + @param seq 请求序列号 + */ + (void)setAlias:(NSString *)alias -callbackSelector:(SEL)cbSelector - object:(id)theTarget; + completion:(JPUSHAliasOperationCompletion)completion + seq:(NSInteger)seq; + +/** + 删除alias + + @param completion 响应回调 + @param seq 请求序列号 + */ ++ (void)deleteAlias:(JPUSHAliasOperationCompletion)completion + seq:(NSInteger)seq; + +/** + 查询当前alias + + @param completion 响应回调 + @param seq 请求序列号 + */ ++ (void)getAlias:(JPUSHAliasOperationCompletion)completion + seq:(NSInteger)seq; + /*! * @abstract 过滤掉无效的 tags @@ -230,7 +296,6 @@ callbackSelector:(SEL)cbSelector */ + (NSSet *)filterValidTags:(NSSet *)tags; - ///---------------------------------------------------- /// @name Stats 统计功能 ///---------------------------------------------------- @@ -471,6 +536,40 @@ callbackSelector:(SEL)cbSelector */ + (void)setLogOFF; + +///---------------------------------------------------- +///********************下列方法已过期******************** +///**************请使用新版tag/alias操作接口************** +///---------------------------------------------------- +/// @name Tag alias setting 设置别名与标签 +///---------------------------------------------------- + +/*! + * 下面的接口是可选的 + * 设置标签和(或)别名(若参数为nil,则忽略;若是空对象,则清空;详情请参考文档:https://docs.jiguang.cn/jpush/client/iOS/ios_api/) + * setTags:alias:fetchCompletionHandle:是新的设置标签别名的方法,不再需要显示声明回调函数,只需要在block里面处理设置结果即可. + * WARN: 使用block时需要注意循环引用问题 + */ ++ (void) setTags:(NSSet *)tags + alias:(NSString *)alias +callbackSelector:(SEL)cbSelector + target:(id)theTarget __attribute__((deprecated("JPush 2.1.1 版本已过期"))); ++ (void) setTags:(NSSet *)tags + alias:(NSString *)alias +callbackSelector:(SEL)cbSelector + object:(id)theTarget __attribute__((deprecated("JPush 3.0.6 版本已过期"))); ++ (void) setTags:(NSSet *)tags +callbackSelector:(SEL)cbSelector + object:(id)theTarget __attribute__((deprecated("JPush 3.0.6 版本已过期"))); ++ (void)setTags:(NSSet *)tags + alias:(NSString *)alias +fetchCompletionHandle:(void (^)(int iResCode, NSSet *iTags, NSString *iAlias))completionHandler __attribute__((deprecated("JPush 3.0.6 版本已过期"))); ++ (void) setTags:(NSSet *)tags +aliasInbackground:(NSString *)alias __attribute__((deprecated("JPush 3.0.6 版本已过期"))); ++ (void)setAlias:(NSString *)alias +callbackSelector:(SEL)cbSelector + object:(id)theTarget __attribute__((deprecated("JPush 3.0.6 版本已过期"))); + @end @class UNUserNotificationCenter; diff --git a/www/JPushPlugin.js b/www/JPushPlugin.js index b639717..4c79699 100644 --- a/www/JPushPlugin.js +++ b/www/JPushPlugin.js @@ -84,12 +84,87 @@ JPushPlugin.prototype.setTagsWithAlias = function (tags, alias, successCallback, this.callNative('setTagsWithAlias', arrayTagWithAlias, successCallback, errorCallback) } -JPushPlugin.prototype.setTags = function (tags, successCallback, errorCallback) { - this.callNative('setTags', tags, successCallback, errorCallback) +/** + * 设置标签。 + * 注意:该接口是覆盖逻辑,而不是增量逻辑。即新的调用会覆盖之前的设置。 + * + * @param params = { 'sequence': number, 'tags': ['tag1', 'tag2'] } + */ +JPushPlugin.prototype.setTags = function (params, successCallback, errorCallback) { + this.callNative('setTags', [params], successCallback, errorCallback) } -JPushPlugin.prototype.setAlias = function (alias, successCallback, errorCallback) { - this.callNative('setAlias', [alias], successCallback, errorCallback) +/** + * 新增标签。 + * + * @param params = { 'sequence': number, 'tags': ['tag1', 'tag2'] } + */ +JPushPlugin.prototype.addTags = function (params, successCallback, errorCallback) { + this.callNative('addTags', [params], successCallback, errorCallback) +} + +/** + * 删除指定标签。 + * + * @param params = { 'sequence': number, 'tags': ['tag1', 'tag2'] } + */ +JPushPlugin.prototype.deleteTags = function (params, successCallback, errorCallback) { + this.callNative('deleteTags', [params], successCallback, errorCallback) +} + +/** + * 清除所有标签。 + * + * @param params = { 'sequence': number } + */ +JPushPlugin.prototype.cleanTags = function (params, successCallback, errorCallback) { + this.callNative('cleanTags', [params], successCallback, errorCallback) +} + +/** + * 查询所有标签。 + * + * @param params = { 'sequence': number } + */ +JPushPlugin.prototype.getAllTags = function (params, successCallback, errorCallback) { + this.callNative('getAllTags', [params], successCallback, errorCallback) +} + +/** + * 查询指定标签与当前用户的绑定状态。 + * + * @param params = { 'sequence': number, 'tag': string } + */ +JPushPlugin.prototype.checkTagBindState = function (params, successCallback, errorCallback) { + this.callNative('checkTagBindState', [params], successCallback, errorCallback) +} + +/** + * 设置别名。 + * 注意:该接口是覆盖逻辑,而不是增量逻辑。即新的调用会覆盖之前的设置。 + * + * @param params = { 'sequence': number, 'alias': string } + */ +JPushPlugin.prototype.setAlias = function (params, successCallback, errorCallback) { + this.callNative('setAlias', [params], successCallback, errorCallback) +} + +/** + * 删除别名。 + * + * @param params = { 'sequence': number } + */ +JPushPlugin.prototype.deleteAlias = function (params, successCallback, errorCallback) { + this.callNative('deleteAlias', [params], successCallback, errorCallback) +} + +/** + * 查询当前绑定的别名。 + * + * @param params = { 'sequence': number } + */ +JPushPlugin.prototype.getAlias = function (params, successCallback, errorCallback) { + this.callNative('getAlias', [params], successCallback, errorCallback) } // 判断系统设置中是否对本应用启用通知。