Merge branch 'dev'

This commit is contained in:
Hevin 2017-09-22 20:24:21 +08:00
commit 4753174bda
13 changed files with 1206 additions and 398 deletions

View File

@ -1,7 +1,7 @@
# JPush PhoneGap / Cordova Plugin # 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) [![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) [![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) [![weibo](https://img.shields.io/badge/weibo-JPush-blue.svg)](http://weibo.com/jpush?refer_flag=1001030101_&is_all=1)

View File

@ -23,7 +23,9 @@
#### 接口定义 #### 接口定义
window.plugins.jPushPlugin.init() ```js
window.JPush.init()
```
### API - stopPush ### API - stopPush
+ Android 平台: + Android 平台:
@ -43,7 +45,9 @@
#### 接口定义 #### 接口定义
window.plugins.jPushPlugin.stopPush() ```js
window.JPush.stopPush()
```
### API - resumePush ### API - resumePush
@ -59,7 +63,7 @@
#### 接口定义 #### 接口定义
window.plugins.jPushPlugin.resumePush() window.JPush.resumePush()
### API - isPushStopped ### 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) { ```js
window.JPush.isPushStopped(function (result) {
if (result == 0) { if (result == 0) {
// 开启 // 开启
} else { } else {
// 关闭 // 关闭
} }
}) })
```
## 开启 Debug 模式 ## 开启 Debug 模式
### API - setDebugMode ### API - setDebugMode
用于开启 Debug 模式,显示更多的日志信息。 用于开启 Debug 模式,显示更多的日志信息。
#### 接口定义 #### 代码示例
JPushPlugin.prototype.setDebugMode(isOpen) ```js
window.JPush.setDebugMode(true)
```
#### 参数说明 #### 参数说明
- isOpen: true开启 Debug 模式false关闭 Debug 模式,不显示错误信息之外的日志信息。 - isOpen: true开启 Debug 模式false关闭 Debug 模式,不显示错误信息之外的日志信息。
#### 代码示例
window.plugins.jPushPlugin.setDebugMode(true)
## 获取 RegistrationID ## 获取 RegistrationID
### API - getRegistrationID ### 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) { ```js
console.log("JPushPlugin:registrationID is " + data) window.JPush.getRegistrationID(function(rId) {
console.log("JPushPlugin:registrationID is " + rId)
}) })
```
## 设置别名与标签 ## 设置别名与标签
### API - setTagsWithAlias, setTags, setAlias
提供几个相关 API 用来设置别名alias与标签tags 提供几个相关 API 用来设置别名alias与标签tags
这几个 API 可以在 App 里任何地方调用。 这几个 API 可以在 App 里任何地方调用。
@ -159,54 +165,200 @@ JPush SDK 会以广播的形式发送 RegistrationID 到应用程序。
举例: game, old_page, women。 举例: game, old_page, women。
#### 接口定义 > 以下方法的错误回调均包含 `sequence``code` 属性。其中 code 为错误码,具体定义可参考[官方文档](https://docs.jiguang.cn/jpush/client/Android/android_api/#_133)。
```js ### setAlias
JPushPlugin.prototype.setTagsWithAlias(tags, alias, successCallback, errorCallback)
JPushPlugin.prototype.setTags(tags, successCallback, errorCallback)
JPushPlugin.prototype.setAlias(alias, successCallback, errorCallback)
```
#### 参数说明 设置别名。注意这个接口是覆盖逻辑,而不是增量逻辑。即新的调用会覆盖之前的设置。
* tags:
* 参数类型为数组。
* nil 此次调用不设置此值。
* 空集合表示取消之前的设置。
* 每次调用至少设置一个 tag覆盖之前的设置不是新增。
* 有效的标签组成:字母(区分大小写)、数字、下划线、汉字。
* 限制:每个 tag 命名长度限制为 40 字节,最多支持设置 100 个 tag但总长度不得超过1K字节判断长度需采用 UTF-8 编码)。
* 单个设备最多支持设置 100 个 tagApp 全局 tag 数量无限制。
* alias:
* 参数类型为字符串。
* nil 此次调用不设置此值。
* 空字符串 "")表示取消之前的设置。
* 有效的别名组成:字母(区分大小写)、数字、下划线、汉字。
* 限制alias 命名长度限制为 40 字节(判断长度需采用 UTF-8 编码)。
#### 代码示例 #### 代码示例
```js ```js
window.plugins.jPushPlugin.setTagsWithAlias([tag1, tag2], alias1, function () { window.JPush.setAlias({ sequence: 1, alias: 'your_alias' },
// success callback. (result) => {
}, function (errorMsg) { var sequence = result.sequence
// errorMsg 格式为 'errorCode: error message'. var alias = result.alias
}, (error) => {
var sequence = error.sequence
var errorCode = error.code
}) })
``` ```
#### 错误码定义 #### 参数说明
|Code|描述 |详细解释 | - sequence: number。用户自定义的操作序列号, 同操作结果一起返回,用来标识一次操作的唯一性。
|----|:----------------------------------------|:--------| - alias: string
|6001|无效的设置tag / alias 不应参数都为 null。 | | - 每次调用设置有效的别名将覆盖之前的设置。
|6002|设置超时。 |建议重试。| - 有效的别名组成:字母(区分大小写)、数字、下划线、汉字、特殊字符@!#$&*+=.|。
|6003|alias 字符串不合法。 |有效的别名、标签组成:字母(区分大小写)、数字、下划线、汉字。| - 限制alias 命名长度限制为 40 字节(判断长度需采用 UTF-8 编码)。
|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 次。 |短时间内操作过于频繁。|
### 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) }, false)
> ps点击通知后传递的 json object 保存在 window.plugins.jPushPlugin.openNotification直接访问即可字段示例根据实际推送情况可能略有差别请注意。 > ps点击通知后传递的 json object 保存在 window.JPush.openNotification直接访问即可字段示例根据实际推送情况可能略有差别请注意。
+ Android: + Android:
@ -280,7 +432,7 @@ window.plugins.jPushPlugin.setTagsWithAlias([tag1, tag2], alias1, function () {
}, false) }, false)
> ps点击通知后传递的 json object 保存在 window.plugins.jPushPlugin.receiveNotification直接访问即可字段示例根据实际推送情况可能略有差别请注意。 > ps点击通知后传递的 json object 保存在 window.JPush.receiveNotification直接访问即可字段示例根据实际推送情况可能略有差别请注意。
+ Android: + Android:
@ -334,7 +486,7 @@ window.plugins.jPushPlugin.setTagsWithAlias([tag1, tag2], alias1, function () {
} }
}, false) }, false)
> ps点击通知后传递的 json object 保存在 window.plugins.jPushPlugin.receiveMessage直接访问即可字段示例根据实际推送情况可能略有差别请注意。 > ps点击通知后传递的 json object 保存在 window.JPush.receiveMessage直接访问即可字段示例根据实际推送情况可能略有差别请注意。
+ Android: + 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) { if(result == 0) {
// 系统设置中已关闭应用推送。 // 系统设置中已关闭应用推送。
} else if(result > 0) { } else if(result > 0) {

View File

@ -10,12 +10,11 @@
<script type="text/javascript" src="cordova.js"></script> <script type="text/javascript" src="cordova.js"></script>
<script type="text/javascript"> <script type="text/javascript">
var onDeviceReady = function() { var onDeviceReady = function() {
console.log("JPushPlugin:Device ready!");
initiateUI(); initiateUI();
}; };
var getRegistrationID = function() { var getRegistrationID = function() {
window.plugins.jPushPlugin.getRegistrationID(onGetRegistrationID); window.JPush.getRegistrationID(onGetRegistrationID);
}; };
var onGetRegistrationID = function(data) { var onGetRegistrationID = function(data) {
@ -25,6 +24,7 @@
if (data.length == 0) { if (data.length == 0) {
var t1 = window.setTimeout(getRegistrationID, 1000); var t1 = window.setTimeout(getRegistrationID, 1000);
} }
$("#registrationId").html(data); $("#registrationId").html(data);
} catch (exception) { } catch (exception) {
console.log(exception); console.log(exception);
@ -87,46 +87,95 @@
var initiateUI = function() { var initiateUI = function() {
try { try {
window.plugins.jPushPlugin.init(); window.JPush.init();
window.setTimeout(getRegistrationID, 1000); window.setTimeout(getRegistrationID, 1000);
if (device.platform != "Android") { if (device.platform != "Android") {
window.plugins.jPushPlugin.setDebugModeFromIos(); window.JPush.setDebugModeFromIos();
window.plugins.jPushPlugin.setApplicationIconBadgeNumber(0); window.JPush.setApplicationIconBadgeNumber(0);
} else { } else {
window.plugins.jPushPlugin.setDebugMode(true); window.JPush.setDebugMode(true);
window.plugins.jPushPlugin.setStatisticsOpen(true); window.JPush.setStatisticsOpen(true);
} }
} catch (exception) { } catch (exception) {
console.log(exception); console.log(exception);
} }
$("#setTagWithAliasButton").click(function(ev) {
try {
var tag1 = $("#tagText1").attr("value");
var tag2 = $("#tagText2").attr("value");
var tag3 = $("#tagText3").attr("value");
var alias = $("#aliasText").attr("value");
var tags = [];
if (tag1 != "") { $("#setTags").click(function(ev) {
tags.push(tag1); try {
var tag1 = $("#tagText1").val()
var tag2 = $("#tagText2").val()
var tag3 = $("#tagText3").val()
var tags = []
if (tag1) {
tags.push(tag1)
} }
if (tag2 != "") { if (tag2) {
tags.push(tag2); tags.push(tag2)
} }
if (tag3 != "") { if (tag3) {
tags.push(tag3); tags.push(tag3)
} }
window.plugins.jPushPlugin.setTagsWithAlias(tags, alias, function () {
// Success callback window.JPush.setTags({ sequence: 1, tags: tags },
console.log(tags + ' - ' + alias) (result) => {
}); $("#tagsResult").html(result.tags)
}, (error) => {
alert(error.code)
})
} catch (exception) { } catch (exception) {
console.log(exception); console.log(exception)
} }
}) })
$("#getAllTags").click(function (event) {
window.JPush.getAllTags({ sequence: 2 },
(result) => {
$("#tagsResult").html(result.tags)
}, (error) => {
alert(error.code)
})
})
$("#cleanTags").click(function (event) {
window.JPush.cleanTags({ sequence: 2 },
(result) => {
alert(result.sequence)
$("#tagsResult").html("")
}, (error) => {
alert(error.code)
})
})
$("#setAlias").click(function (event) {
var alias = $("#aliasText").val()
window.JPush.setAlias({ sequence: 1, alias: alias },
(result) => {
$("#aliasResult").html(result.alias)
}, (error) => {
alert(error.code)
})
})
$("#getAlias").click(function (event) {
window.JPush.getAlias({ sequence: 2 },
(result) => {
alert(JSON.stringify(result));
}, (error) => {
alert(error.code)
})
});
$("#deleteAlias").click(function (event) {
window.JPush.deleteAlias({ sequence: 3 },
(result) => {
alert(JSON.stringify(result));
}, (error) => {
alert(error.code)
})
});
}; };
document.addEventListener("jpush.setTagsWithAlias", onTagsWithAlias, false);
document.addEventListener("deviceready", onDeviceReady, false); document.addEventListener("deviceready", onDeviceReady, false);
document.addEventListener("jpush.openNotification", onOpenNotification, false); document.addEventListener("jpush.openNotification", onOpenNotification, false);
document.addEventListener("jpush.receiveNotification", onReceiveNotification, false); document.addEventListener("jpush.receiveNotification", onReceiveNotification, false);
@ -176,13 +225,26 @@
</tr> </tr>
</table> </table>
</div> </div>
<div data-role="fieldcontain"> <div data-role="fieldcontain">
<input type="button" id="setTagWithAliasButton" <input type="button" id="setTags" value="Set tags" />
value="Add tag and alias" /> <input type="button" id="getAllTags" value="Get all tags" />
<input type="button" id="cleanTags" value="Clean tags" />
</div>
<div data-role="fieldcontain">
<input type="button" id="setAlias" value="Set alias" />
<input type="button" id="getAlias" value="Get alias" />
<input type="button" id="deleteAlias" value="Delete alias" />
</div>
<div data-role="fieldcontain">
<label id="tagsPrompt">设置 Tag 的结果:</label>
<label id="tagsResult">null</label>
</div> </div>
<div data-role="fieldcontain"> <div data-role="fieldcontain">
<label id="tagAliasPrompt">设置tag/alias结果:</label> <label id="aliasPrompt">设置 Alias 的结果:</label>
<label id="tagAliasResult">null</label> <label id="aliasResult">null</label>
</div> </div>
<div data-role="fieldcontain"> <div data-role="fieldcontain">
<label id="notificationPrompt">接受的通知内容:</label> <label id="notificationPrompt">接受的通知内容:</label>
@ -197,5 +259,4 @@
</div> </div>
</div> </div>
</body> </body>
</html> </html>

View File

@ -1,6 +1,6 @@
{ {
"name": "jpush-phonegap-plugin", "name": "jpush-phonegap-plugin",
"version": "3.2.3", "version": "3.2.4",
"description": "JPush for cordova plugin", "description": "JPush for cordova plugin",
"cordova": { "cordova": {
"id": "jpush-phonegap-plugin", "id": "jpush-phonegap-plugin",

View File

@ -2,7 +2,7 @@
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0" <plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
id="jpush-phonegap-plugin" id="jpush-phonegap-plugin"
version="3.2.3"> version="3.2.4">
<name>JPush</name> <name>JPush</name>
<description>JPush for cordova plugin</description> <description>JPush for cordova plugin</description>
@ -192,10 +192,11 @@
<meta-data android:name="JPUSH_APPKEY" android:value="$APP_KEY" /> <meta-data android:name="JPUSH_APPKEY" android:value="$APP_KEY" />
</config-file> </config-file>
<source-file src="src/android/libs/jpush-android_v3.0.6.jar" target-dir="libs" /> <source-file src="src/android/libs/jpush-android-3.0.8.jar" target-dir="libs" />
<source-file src="src/android/MyReceiver.java" target-dir="src/cn/jiguang/cordova/push" /> <source-file src="src/android/MyReceiver.java" target-dir="src/cn/jiguang/cordova/push" />
<source-file src="src/android/JPushPlugin.java" target-dir="src/cn/jiguang/cordova/push" /> <source-file src="src/android/JPushPlugin.java" target-dir="src/cn/jiguang/cordova/push" />
<source-file src="src/android/JPushEventReceiver.java" target-dir="src/cn/jiguang/cordova/push" />
<source-file src="src/android/res/drawable-hdpi/jpush_richpush_btn_selector.xml" <source-file src="src/android/res/drawable-hdpi/jpush_richpush_btn_selector.xml"
target-dir="res/drawable" /> target-dir="res/drawable" />

View File

@ -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<String> 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);
}
}

View File

@ -35,53 +35,29 @@ import cn.jpush.android.api.BasicPushNotificationBuilder;
import cn.jpush.android.api.JPushInterface; import cn.jpush.android.api.JPushInterface;
import cn.jpush.android.api.TagAliasCallback; import cn.jpush.android.api.TagAliasCallback;
import cn.jpush.android.data.JPushLocalNotification; import cn.jpush.android.data.JPushLocalNotification;
import cn.jpush.android.service.JPushMessageReceiver;
public class JPushPlugin extends CordovaPlugin { public class JPushPlugin extends CordovaPlugin {
private final static List<String> 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 ExecutorService threadPool = Executors.newFixedThreadPool(1);
private Context mContext;
private static JPushPlugin instance; private static JPushPlugin instance;
private static Activity cordovaActivity; private static Activity cordovaActivity;
private static String TAG = "JPushPlugin"; private static String TAG = "JPushPlugin";
private static boolean shouldCacheMsg = false;
private static boolean isStatisticsOpened = false; // 是否开启统计分析功能 private static boolean isStatisticsOpened = false; // 是否开启统计分析功能
public static String notificationTitle; static String notificationTitle;
public static String notificationAlert; static String notificationAlert;
public static Map<String, Object> notificationExtras = new HashMap<String, Object>(); static Map<String, Object> notificationExtras = new HashMap<String, Object>();
public static String openNotificationTitle; static String openNotificationTitle;
public static String openNotificationAlert; static String openNotificationAlert;
public static Map<String, Object> openNotificationExtras = new HashMap<String, Object>(); static Map<String, Object> openNotificationExtras = new HashMap<String, Object>();
static Map<Integer, CallbackContext> eventCallbackMap = new HashMap<Integer, CallbackContext>();
public JPushPlugin() { public JPushPlugin() {
instance = this; instance = this;
@ -89,10 +65,10 @@ public class JPushPlugin extends CordovaPlugin {
@Override @Override
public void initialize(CordovaInterface cordova, CordovaWebView webView) { public void initialize(CordovaInterface cordova, CordovaWebView webView) {
Log.i(TAG, "JPush initialize.");
super.initialize(cordova, webView); super.initialize(cordova, webView);
JPushInterface.init(cordova.getActivity().getApplicationContext()); mContext = cordova.getActivity().getApplicationContext();
JPushInterface.init(mContext);
cordovaActivity = cordova.getActivity(); cordovaActivity = cordova.getActivity();
@ -110,17 +86,12 @@ public class JPushPlugin extends CordovaPlugin {
} }
public void onPause(boolean multitasking) { public void onPause(boolean multitasking) {
Log.i(TAG, "---------------- onPause");
shouldCacheMsg = true;
if (isStatisticsOpened && multitasking) { if (isStatisticsOpened && multitasking) {
JPushInterface.onPause(this.cordova.getActivity()); JPushInterface.onPause(this.cordova.getActivity());
} }
} }
public void onResume(boolean multitasking) { public void onResume(boolean multitasking) {
shouldCacheMsg = false;
Log.i(TAG, "---------------- onResume" + "-" + openNotificationAlert
+ "-" + notificationAlert);
if (isStatisticsOpened && multitasking) { if (isStatisticsOpened && multitasking) {
JPushInterface.onResume(this.cordova.getActivity()); JPushInterface.onResume(this.cordova.getActivity());
} }
@ -142,15 +113,14 @@ public class JPushPlugin extends CordovaPlugin {
instance = null; instance = null;
} }
private static JSONObject getMessageObject(String message, private static JSONObject getMessageObject(String message, Map<String, Object> extras) {
Map<String, Object> extras) {
JSONObject data = new JSONObject(); JSONObject data = new JSONObject();
try { try {
data.put("message", message); data.put("message", message);
JSONObject jExtras = new JSONObject(); JSONObject jExtras = new JSONObject();
for (Entry<String, Object> entry : extras.entrySet()) { for (Entry<String, Object> entry : extras.entrySet()) {
if (entry.getKey().equals("cn.jpush.android.EXTRA")) { if (entry.getKey().equals("cn.jpush.android.EXTRA")) {
JSONObject jo = null; JSONObject jo;
if (TextUtils.isEmpty((String) entry.getValue())) { if (TextUtils.isEmpty((String) entry.getValue())) {
jo = new JSONObject(); jo = new JSONObject();
} else { } else {
@ -176,8 +146,7 @@ public class JPushPlugin extends CordovaPlugin {
return data; return data;
} }
private static JSONObject getNotificationObject(String title, private static JSONObject getNotificationObject(String title, String alert, Map<String, Object> extras) {
String alert, Map<String, Object> extras) {
JSONObject data = new JSONObject(); JSONObject data = new JSONObject();
try { try {
data.put("title", title); data.put("title", title);
@ -226,8 +195,7 @@ public class JPushPlugin extends CordovaPlugin {
}); });
} }
static void transmitNotificationOpen(String title, String alert, static void transmitNotificationOpen(String title, String alert, Map<String, Object> extras) {
Map<String, Object> extras) {
if (instance == null) { if (instance == null) {
return; return;
} }
@ -244,8 +212,7 @@ public class JPushPlugin extends CordovaPlugin {
JPushPlugin.openNotificationAlert = null; JPushPlugin.openNotificationAlert = null;
} }
static void transmitNotificationReceive(String title, String alert, static void transmitNotificationReceive(String title, String alert, Map<String, Object> extras) {
Map<String, Object> extras) {
if (instance == null) { if (instance == null) {
return; return;
} }
@ -285,9 +252,6 @@ public class JPushPlugin extends CordovaPlugin {
@Override @Override
public boolean execute(final String action, final JSONArray data, public boolean execute(final String action, final JSONArray data,
final CallbackContext callbackContext) throws JSONException { final CallbackContext callbackContext) throws JSONException {
if (!methodList.contains(action)) {
return false;
}
threadPool.execute(new Runnable() { threadPool.execute(new Runnable() {
@Override @Override
public void run() { public void run() {
@ -304,7 +268,7 @@ public class JPushPlugin extends CordovaPlugin {
} }
void init(JSONArray data, CallbackContext callbackContext) { void init(JSONArray data, CallbackContext callbackContext) {
JPushInterface.init(this.cordova.getActivity().getApplicationContext()); JPushInterface.init(mContext);
} }
void setDebugMode(JSONArray data, CallbackContext callbackContext) { void setDebugMode(JSONArray data, CallbackContext callbackContext) {
@ -319,18 +283,17 @@ public class JPushPlugin extends CordovaPlugin {
} }
void stopPush(JSONArray data, CallbackContext callbackContext) { void stopPush(JSONArray data, CallbackContext callbackContext) {
JPushInterface.stopPush(this.cordova.getActivity().getApplicationContext()); JPushInterface.stopPush(mContext);
callbackContext.success(); callbackContext.success();
} }
void resumePush(JSONArray data, CallbackContext callbackContext) { void resumePush(JSONArray data, CallbackContext callbackContext) {
JPushInterface.resumePush(this.cordova.getActivity().getApplicationContext()); JPushInterface.resumePush(mContext);
callbackContext.success(); callbackContext.success();
} }
void isPushStopped(JSONArray data, CallbackContext callbackContext) { void isPushStopped(JSONArray data, CallbackContext callbackContext) {
boolean isStopped = JPushInterface.isPushStopped( boolean isStopped = JPushInterface.isPushStopped(mContext);
this.cordova.getActivity().getApplicationContext());
if (isStopped) { if (isStopped) {
callbackContext.success(1); callbackContext.success(1);
} else { } else {
@ -358,7 +321,7 @@ public class JPushPlugin extends CordovaPlugin {
} }
if (num != -1) { if (num != -1) {
JPushInterface.setLatestNotificationNumber( JPushInterface.setLatestNotificationNumber(
this.cordova.getActivity().getApplicationContext(), num); mContext, num);
} else { } else {
callbackContext.error("error num"); callbackContext.error("error num");
} }
@ -384,13 +347,13 @@ public class JPushPlugin extends CordovaPlugin {
} catch (JSONException e) { } catch (JSONException e) {
callbackContext.error("error reading hour json"); callbackContext.error("error reading hour json");
} }
Context context = this.cordova.getActivity().getApplicationContext(); Context context = mContext;
JPushInterface.setPushTime(context, days, startHour, endHour); JPushInterface.setPushTime(context, days, startHour, endHour);
callbackContext.success(); callbackContext.success();
} }
void getRegistrationID(JSONArray data, CallbackContext callbackContext) { void getRegistrationID(JSONArray data, CallbackContext callbackContext) {
Context context = this.cordova.getActivity().getApplicationContext(); Context context = mContext;
String regID = JPushInterface.getRegistrationID(context); String regID = JPushInterface.getRegistrationID(context);
callbackContext.success(regID); 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 { try {
HashSet<String> tags = new HashSet<String>(); JSONObject params = data.getJSONObject(0);
for (int i = 0; i < data.length(); i++) { sequence = params.getInt("sequence");
tags.add(data.getString(i)); alias = params.getString("alias");
}
JPushInterface.setTags(this.cordova.getActivity().getApplicationContext(),
tags, mTagWithAliasCallback);
callbackContext.success();
} catch (JSONException e) { } catch (JSONException e) {
e.printStackTrace(); e.printStackTrace();
callbackContext.error("Error reading tags JSON"); callbackContext.error("Parameters error.");
}
} }
void setAlias(JSONArray data, CallbackContext callbackContext) { JPushInterface.setAlias(mContext, sequence, alias);
eventCallbackMap.put(sequence, callbackContext);
}
void deleteAlias(JSONArray data, CallbackContext callbackContext) {
int sequence = -1;
try { try {
String alias = data.getString(0); JSONObject params = data.getJSONObject(0);
JPushInterface.setAlias(this.cordova.getActivity().getApplicationContext(), sequence = params.getInt("sequence");
alias, mTagWithAliasCallback);
callbackContext.success();
} catch (JSONException e) { } catch (JSONException e) {
e.printStackTrace(); 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<String> tags = new HashSet<String>();
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<String> tags = new HashSet<String>();
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<String> tags = new HashSet<String>();
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) { void setTagsWithAlias(JSONArray data, CallbackContext callbackContext) {
@ -449,7 +548,7 @@ public class JPushPlugin extends CordovaPlugin {
for (int i = 0; i < tagsArray.length(); i++) { for (int i = 0; i < tagsArray.length(); i++) {
tags.add(tagsArray.getString(i)); tags.add(tagsArray.getString(i));
} }
JPushInterface.setAliasAndTags(this.cordova.getActivity().getApplicationContext(), JPushInterface.setAliasAndTags(mContext,
alias, tags, mTagWithAliasCallback); alias, tags, mTagWithAliasCallback);
callbackContext.success(); callbackContext.success();
} catch (JSONException e) { } catch (JSONException e) {
@ -513,8 +612,7 @@ public class JPushPlugin extends CordovaPlugin {
} }
} }
void addLocalNotification(JSONArray data, CallbackContext callbackContext) void addLocalNotification(JSONArray data, CallbackContext callbackContext) throws JSONException {
throws JSONException {
int builderId = data.getInt(0); int builderId = data.getInt(0);
String content = data.getString(1); String content = data.getString(1);
String title = data.getString(2); String title = data.getString(2);
@ -537,8 +635,7 @@ public class JPushPlugin extends CordovaPlugin {
JPushInterface.addLocalNotification(this.cordova.getActivity(), ln); JPushInterface.addLocalNotification(this.cordova.getActivity(), ln);
} }
void removeLocalNotification(JSONArray data, CallbackContext callbackContext) void removeLocalNotification(JSONArray data, CallbackContext callbackContext) throws JSONException {
throws JSONException {
int notificationID = data.getInt(0); int notificationID = data.getInt(0);
JPushInterface.removeLocalNotification(this.cordova.getActivity(), notificationID); JPushInterface.removeLocalNotification(this.cordova.getActivity(), notificationID);
} }
@ -634,7 +731,7 @@ public class JPushPlugin extends CordovaPlugin {
String pkg = context.getPackageName(); String pkg = context.getPackageName();
int uid = appInfo.uid; int uid = appInfo.uid;
Class appOpsClazz = null; Class appOpsClazz;
try { try {
appOpsClazz = Class.forName(AppOpsManager.class.getName()); appOpsClazz = Class.forName(AppOpsManager.class.getName());

Binary file not shown.

View File

@ -18,8 +18,17 @@
//以下为js中可调用接口 //以下为js中可调用接口
//设置标签、别名 //设置标签、别名
-(void)setTagsWithAlias:(CDVInvokedUrlCommand*)command; -(void)setTagsWithAlias:(CDVInvokedUrlCommand*)command;
-(void)setTags:(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)setAlias:(CDVInvokedUrlCommand*)command;
-(void)deleteAlias:(CDVInvokedUrlCommand*)command;
-(void)getAlias:(CDVInvokedUrlCommand*)command;
//获取 RegistrationID //获取 RegistrationID
-(void)getRegistrationID:(CDVInvokedUrlCommand*)command; -(void)getRegistrationID:(CDVInvokedUrlCommand*)command;

View File

@ -1,12 +1,3 @@
//
// PushTalkPlugin.m
// PushTalk
//
// Created by zhangqinghe on 13-12-13.
//
//
#import "JPushPlugin.h" #import "JPushPlugin.h"
#import "JPUSHService.h" #import "JPUSHService.h"
#import <UIKit/UIKit.h> #import <UIKit/UIKit.h>
@ -114,33 +105,209 @@
} }
-(void)setTags:(CDVInvokedUrlCommand*)command { -(void)setTags:(CDVInvokedUrlCommand*)command {
NSArray *tags = command.arguments; NSDictionary* params = [command.arguments objectAtIndex:0];
NSNumber* sequence = params[@"sequence"];
NSArray* tags = params[@"tags"];
[JPUSHService setTags:[NSSet setWithArray:tags] [JPUSHService setTags:[NSSet setWithArray:tags]
alias:nil completion:^(NSInteger iResCode, NSSet *iTags, NSInteger seq) {
fetchCompletionHandle:^(int iResCode, NSSet *iTags, NSString *iAlias) { NSMutableDictionary* dic = [[NSMutableDictionary alloc] init];
[dic setObject:sequence forKey:@"sequence"];
CDVPluginResult* result; CDVPluginResult* result;
if (iResCode == 0) { if (iResCode == 0) {
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:nil]; [dic setObject:[iTags allObjects] forKey:@"tags"];
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:dic];
} else { } 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]; [self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
}]; } seq:[sequence integerValue]];
}
-(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 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)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 { -(void)setAlias:(CDVInvokedUrlCommand*)command {
NSString *alias = [command argumentAtIndex:0]; NSDictionary* params = [command.arguments objectAtIndex:0];
[JPUSHService setTags:nil NSNumber* sequence = params[@"sequence"];
alias:alias NSString* alias = params[@"alias"];
fetchCompletionHandle:^(int iResCode, NSSet *iTags, NSString *iAlias) {
[JPUSHService setAlias:alias completion:^(NSInteger iResCode, NSString *iAlias, NSInteger seq) {
NSMutableDictionary* dic = [[NSMutableDictionary alloc] init];
[dic setObject:sequence forKey:@"sequence"];
CDVPluginResult* result; CDVPluginResult* result;
if (iResCode == 0) { if (iResCode == 0) {
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:nil]; [dic setObject:iAlias forKey:@"alias"];
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:dic];
} else { } 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]; [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{ -(void)getRegistrationID:(CDVInvokedUrlCommand*)command{
@ -346,15 +513,6 @@
[self.commandDelegate sendPluginResult:result callbackId:command.callbackId]; [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) { if (notification && notification.userInfo) {
[JPushPlugin fireDocumentEvent:JPushDocumentEvent_ReceiveMessage [JPushPlugin fireDocumentEvent:JPushDocumentEvent_ReceiveMessage

157
src/ios/lib/JPUSHService.h Normal file → Executable file
View File

@ -9,7 +9,7 @@
* Copyright (c) 2011 ~ 2017 Shenzhen HXHG. All rights reserved. * Copyright (c) 2011 ~ 2017 Shenzhen HXHG. All rights reserved.
*/ */
#define JPUSH_VERSION_NUMBER 3.0.5 #define JPUSH_VERSION_NUMBER 3.0.6
#import <Foundation/Foundation.h> #import <Foundation/Foundation.h>
@ -22,6 +22,10 @@
@class UNNotification; @class UNNotification;
@protocol JPUSHRegisterDelegate; @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 kJPFNetworkIsConnectingNotification; // 正在连接中
extern NSString *const kJPFNetworkDidSetupNotification; // 建立连接 extern NSString *const kJPFNetworkDidSetupNotification; // 建立连接
extern NSString *const kJPFNetworkDidCloseNotification; // 关闭连接 extern NSString *const kJPFNetworkDidCloseNotification; // 关闭连接
@ -137,6 +141,7 @@ typedef NS_OPTIONS(NSUInteger, JPAuthorizationOptions) {
* @param appKey JPush ,. JPush . * @param appKey JPush ,. JPush .
* @param channel . . * @param channel . .
* @param isProduction . , NO; , YES. * @param isProduction . , NO; , YES.
* App profile provision的配置.
* @param advertisingIdentifier 广IDFA 使IDFAnil. * @param advertisingIdentifier 广IDFA 使IDFAnil.
* *
* @discussion SDK启动必须的参数, SDK. * @discussion SDK启动必须的参数, SDK.
@ -186,41 +191,102 @@ typedef NS_OPTIONS(NSUInteger, JPAuthorizationOptions) {
*/ */
+ (void)handleRemoteNotification:(NSDictionary *)remoteInfo; + (void)handleRemoteNotification:(NSDictionary *)remoteInfo;
///----------------------------------------------------
/// @name Tag alias setting 设置别名与标签
///----------------------------------------------------
/*! /*!
* * Tags操作接口
* ()nilhttps://docs.jiguang.cn/jpush/client/iOS/ios_api/ * ////
* setTags:alias:fetchCompletionHandle:block里面处理设置结果即可. * https://docs.jiguang.cn/jpush/client/iOS/ios_api/
* 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 tags
callbackSelector:(SEL)cbSelector
object:(id)theTarget;
+ (void) setTags:(NSSet *)tags @param tags tags集合
callbackSelector:(SEL)cbSelector @param completion
object:(id)theTarget; @param seq
*/
+ (void)addTags:(NSSet<NSString *> *)tags
completion:(JPUSHTagsOperationCompletion)completion
seq:(NSInteger)seq;
+ (void)setTags:(NSSet *)tags /**
alias:(NSString *)alias tags
fetchCompletionHandle:(void (^)(int iResCode, NSSet *iTags, NSString *iAlias))completionHandler; tags
+ (void) setTags:(NSSet *)tags @param tags tags集合
aliasInbackground:(NSString *)alias; @param completion
@param seq
*/
+ (void)setTags:(NSSet<NSString *> *)tags
completion:(JPUSHTagsOperationCompletion)completion
seq:(NSInteger)seq;
/**
tags
@param tags tags集合
@param completion
@param seq
*/
+ (void)deleteTags:(NSSet<NSString *> *)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 + (void)setAlias:(NSString *)alias
callbackSelector:(SEL)cbSelector completion:(JPUSHAliasOperationCompletion)completion
object:(id)theTarget; 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 * @abstract tags
@ -230,7 +296,6 @@ callbackSelector:(SEL)cbSelector
*/ */
+ (NSSet *)filterValidTags:(NSSet *)tags; + (NSSet *)filterValidTags:(NSSet *)tags;
///---------------------------------------------------- ///----------------------------------------------------
/// @name Stats 统计功能 /// @name Stats 统计功能
///---------------------------------------------------- ///----------------------------------------------------
@ -471,6 +536,40 @@ callbackSelector:(SEL)cbSelector
*/ */
+ (void)setLogOFF; + (void)setLogOFF;
///----------------------------------------------------
///********************下列方法已过期********************
///**************请使用新版tag/alias操作接口**************
///----------------------------------------------------
/// @name Tag alias setting 设置别名与标签
///----------------------------------------------------
/*!
*
* ()nilhttps://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 @end
@class UNUserNotificationCenter; @class UNUserNotificationCenter;

View File

@ -84,12 +84,87 @@ JPushPlugin.prototype.setTagsWithAlias = function (tags, alias, successCallback,
this.callNative('setTagsWithAlias', arrayTagWithAlias, successCallback, errorCallback) 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)
} }
// 判断系统设置中是否对本应用启用通知。 // 判断系统设置中是否对本应用启用通知。