Compare commits

...

16 Commits

Author SHA1 Message Date
darkterrorooo
4d0ff548b8 Merge pull request #114 from darkterrorooo/master
升级 android sdk to 2.0.6
2016-01-21 17:28:52 +08:00
darkterrorooo
83e86b64de 升级 android sdk to 2.0.6 2016-01-21 17:20:31 +08:00
darkterrorooo
d5cf71ed1e Merge pull request #103 from darkterrorooo/master
1,升级 iOS 推送库至 2.1.0
2,兼容 Cordova-ios 4.0
3 ,增加接口 getApplicationIconBadgeNumber 获取iOS应用本地角标值
2016-01-21 15:31:25 +08:00
darkterrorooo
1536d737ad 升级ios 库到 2.1.0 2016-01-21 15:23:53 +08:00
darkterrorooo
3f9454edf3 升级ios 库到 2.1.0 2016-01-21 15:15:48 +08:00
darkterrorooo
3d46fbc9ba fix version 2015-12-17 18:06:55 +08:00
darkterrorooo
6f826ca9ba Merge pull request #102 from annilq/patch-1
错别字
2015-12-16 15:04:21 +08:00
annilq
f2eb889584 错别字 2015-12-16 14:46:15 +08:00
darkterrorooo
34c316af7e Merge pull request #101 from darkterrorooo/master
fix #72 #99
2015-12-11 00:52:43 +08:00
darkterrorooo
e7bedc78f7 fix #72 #99 2015-12-11 00:45:49 +08:00
darkterrorooo
23fd3bc0cb fix #72 #99 2015-12-11 00:38:48 +08:00
darkterrorooo
5e44499ff5 fix #72 #99 2015-12-11 00:34:55 +08:00
darkterrorooo
b13aabe2bc fix tortuous 2015-12-09 18:51:56 +08:00
darkterrorooo
7cb3e22e14 Merge pull request #100 from darkterrorooo/master
fix #99 android jpush.openNotification 事件调用两次
2015-12-09 18:42:35 +08:00
darkterrorooo
a3ad96f786 fix tortuous 2015-12-09 18:27:08 +08:00
darkterrorooo
42d64ca2f0 fix android openNotification twice 2015-12-09 17:55:10 +08:00
21 changed files with 1119 additions and 717 deletions

View File

@@ -1,6 +1,17 @@
l## JPush PhoneGap Plugin ##
## JPush PhoneGap Plugin ##
jpush-phonegap-plugin 支持 iOS,Android 的推送插件。
**功能特性:**
>+ 发送推送通知
+ 发送推送自定义消息
+ 设置推送标签和别名
+ 设置角标iOS
*如需要 IM 功能插件,请关注[jmessage-phonegap-plugin](https://github.com/jpush/jmessage-phonegap-plugin)*
## 安装 ##
###准备工作
1. cordova create 文件夹名字 包名 应用名字
@@ -68,12 +79,6 @@ l## JPush PhoneGap Plugin ##
该项目基于cordova实现目前无法使用'phonegap build'云服务进行打包,建议使用本地环境进行打包
###常见错误
1. androd
eclipse中phonegap工程import之后出现:`Type CallbackContext cannot be resolved to a type`
解决方案eclipse中右键单击工程名Build Path->Config Build Path->Projects->选中 工程名称CordovaLib->点击 add
### API说明
插件的API集中在JPushPlugin.js文件中,这个文件的位置如下
@@ -188,5 +193,20 @@ l## JPush PhoneGap Plugin ##
[Android API详细说明](document/Android_detail_api.md)
###常见问题
####1. androd
eclipse中phonegap工程import之后出现:`Type CallbackContext cannot be resolved to a type`
解决方案eclipse中右键单击工程名Build Path->Config Build Path->Projects->选中 工程名称CordovaLib->点击 add
####2. iOS 设置/修改 APP_KEY
在PushConfig.plist 中修改。PushConfig.plist 其他值说明:
CHANNEL 渠道标识
IsProduction 是否生产环境(暂未启用)
###更多
[JPush官网文档](http://docs.jpush.io/)

View File

@@ -271,7 +271,7 @@ ps点击通知后传递的json object 保存在window.plugins.jPushPlugin.ope
#### event - jpush.receiveNotification
点击通知进入应用程序时会出发改事件
点击通知进入应用程序时会触发该事件
#####代码示例

View File

@@ -52,7 +52,8 @@ duration 自定义的页面时间
### 设置Badge
#### API - setBadge,resetBadge
badge是iOS用来标记应用程序状态的一个数字出现在程序图标右上角。 JPush封装badge功能允许应用上传badge值至JPush服务器由JPush后台帮助管理每个用户所对应的推送badge值简化了设置推送badge的操作。
JPush封装badge功能允许应用上传badge值至JPush服务器由JPush后台帮助管理每个用户所对应的推送badge值简化了设置推送badge的操作。
(本接口不会直接改变应用本地的角标值. 要修改本地badege值使用 setApplicationIconBadgeNumber
实际应用中开发者可以直接对badge值做增减操作无需自己维护用户与badge值之间的对应关系。
##### 接口定义
@@ -74,6 +75,7 @@ value 取值范围:[0,99999]
#### API - setApplicationIconBadgeNumber
本接口直接改变应用本地的角标值.
设置iOS的角标当设置badge0时为清除角标
##### 接口定义
@@ -92,6 +94,27 @@ value 取值范围:[0,99999]
}
#### API - getApplicationIconBadgeNumber
获取iOS的角标值
##### 接口定义
window.plugins.jPushPlugin.getApplicationIconBadgeNumber(callback)
##### 参数说明
- callback 回调函数
#####代码示例
```
window.plugins.jPushPlugin.getApplicationIconBadgeNumber(function(data){
console.log(data);
});
```
### 本地通知
### 日志等级设置

View File

@@ -1,210 +1,224 @@
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Phonegap Sample App</title>
<link href="css/jquery.mobile-1.1.1.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript" src="js/jquery.mobile-1.1.1.js"></script>
<script type="text/javascript" src="cordova.js"></script>
<script type="text/javascript">
var onDeviceReady = function(){
console.log("JPushPlugin:Device ready!")
initiateUI();
}
var onGetRegistradionID = function(data) {
try{
console.log("JPushPlugin:registrationID is "+data)
$("#registrationid").html(data);
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Phonegap Sample App</title>
<link href="css/jquery.mobile-1.1.1.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript" src="js/jquery.mobile-1.1.1.js"></script>
<script type="text/javascript" src="cordova.js"></script>
<script type="text/javascript">
var onDeviceReady = function () {
console.log("JPushPlugin:Device ready!");
initiateUI();
};
function getRegistrationID() {
window.plugins.jPushPlugin.getRegistrationID(onGetRegistradionID);
}
var onGetRegistradionID = function (data) {
try {
console.log("JPushPlugin:registrationID is " + data);
if (data.length == 0) {
var t1 = window.setTimeout(getRegistrationID, 1000);
}
catch(exception){
$("#registrationid").html(data);
}
catch (exception) {
console.log(exception);
}
};
var onTagsWithAlias = function (event) {
try {
console.log("onTagsWithAlias");
var result = "result code:" + event.resultCode + " ";
result += "tags:" + event.tags + " ";
result += "alias:" + event.alias + " ";
$("#tagAliasResult").html(result);
}
catch (exception) {
console.log(exception)
}
};
var onOpenNotification = function (event) {
try {
var alertContent;
if (device.platform == "Android") {
alertContent = window.plugins.jPushPlugin.openNotification.alert;
} else {
alertContent = event.aps.alert;
}
alert("open Notificaiton:" + alertContent);
}
catch (exception) {
console.log("JPushPlugin:onOpenNotification" + exception);
}
};
var onReceiveNotification = function (event) {
try {
var alertContent;
if (device.platform == "Android") {
alertContent = window.plugins.jPushPlugin.receiveNotification.alert;
} else {
alertContent = event.aps.alert;
}
$("#notificationResult").html(alertContent);
}
catch (exeption) {
console.log(exception)
}
};
var onReceiveMessage = function (event) {
try {
var message;
if (device.platform == "Android") {
message = window.plugins.jPushPlugin.receiveMessage.message;
} else {
message = event.content;
}
//var extras = window.plugins.jPushPlugin.extras
$("#messageResult").html(message);
}
catch (exception) {
console.log("JPushPlugin:onReceiveMessage-->" + exception);
}
};
var initiateUI = function () {
try {
window.plugins.jPushPlugin.init();
getRegistrationID();
if (device.platform != "Android") {
window.plugins.jPushPlugin.setDebugModeFromIos();
window.plugins.jPushPlugin.setApplicationIconBadgeNumber(0);
} else {
window.plugins.jPushPlugin.setDebugMode(true);
}
}
catch (exception) {
console.log(exception);
}
$("#setTagWithAliasButton").click(function (ev) {
// window.plugins.jPushPlugin.getApplicationIconBadgeNumber(function(data){
// console.log(data);
// });
try {
var tag1 = $("#tagText1").attr("value");
var tag2 = $("#tagText2").attr("value");
var tag3 = $("#tagText3").attr("value");
var alias = $("#aliasText").attr("value");
var dd = [];
if (tag1 == "" && tag2 == "" && tag3 == "") {
}
else {
if (tag1 != "") {
dd.push(tag1);
}
if (tag2 != "") {
dd.push(tag2);
}
if (tag3 != "") {
dd.push(tag3);
}
}
window.plugins.jPushPlugin.setTagsWithAlias(dd, alias);
}
catch (exception) {
console.log(exception);
}
}
var onTagsWithAlias = function(event){
try{
console.log("onTagsWithAlias");
var result="result code:"+event.resultCode+" ";
result+="tags:"+event.tags+" ";
result+="alias:"+event.alias+" ";
$("#tagAliasResult").html(result);
}
catch(exception){
console.log(exception)
}
}
var onOpenNotification = function(event){
try{
var alertContent
if(device.platform == "Android"){
alertContent=window.plugins.jPushPlugin.openNotification.alert;
}else{
alertContent = event.aps.alert;
}
alert("open Notificaiton:"+alertContent);
}
catch(exception){
console.log("JPushPlugin:onOpenNotification"+exception);
}
}
var onReceiveNotification = function(event){
try{
var alert
if(device.platform == "Android"){
alert = window.plugins.jPushPlugin.receiveNotification.alert;
}else{
alert = event.aps.alert;
}
$("#notificationResult").html(alert);
}
catch(exeption){
console.log(exception)
}
}
var onReceiveMessage = function(event){
try{
var message
if(device.platform == "Android"){
message = window.plugins.jPushPlugin.receiveMessage.message;
}else{
message = event.content;
}
//var extras = window.plugins.jPushPlugin.extras
$("#messageResult").html(message);
}
catch(exception){
console.log("JPushPlugin:onReceiveMessage-->"+exception);
}
}
var initiateUI = function(){
try{
window.plugins.jPushPlugin.init();
window.plugins.jPushPlugin.getRegistrationID(onGetRegistradionID);
if(device.platform != "Android"){
window.plugins.jPushPlugin.setDebugModeFromIos();
window.plugins.jPushPlugin.setApplicationIconBadgeNumber(0);
}else{
window.plugins.jPushPlugin.setDebugMode(true);
}
}
catch(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 dd = [];
if(tag1==""&&tag2==""&&tag3==""){
}
else{
if(tag1 != ""){
dd.push(tag1);
}
if(tag2 != ""){
dd.push(tag2);
}
if(tag3 != ""){
dd.push(tag3);
}
}
window.plugins.jPushPlugin.setTagsWithAlias(dd,alias);
}
catch(exception){
console.log(exception);
}
})
}
document.addEventListener("jpush.setTagsWithAlias", onTagsWithAlias, false);
document.addEventListener("deviceready", onDeviceReady, false);
document.addEventListener("jpush.openNotification", onOpenNotification, false);
document.addEventListener("jpush.receiveNotification", onReceiveNotification, false);
document.addEventListener("jpush.receiveMessage", onReceiveMessage, false);
})
};
document.addEventListener("jpush.setTagsWithAlias", onTagsWithAlias, false);
document.addEventListener("deviceready", onDeviceReady, false);
document.addEventListener("jpush.openNotification", onOpenNotification, false);
document.addEventListener("jpush.receiveNotification", onReceiveNotification, false);
document.addEventListener("jpush.receiveMessage", onReceiveMessage, false);
//jpush.receiveMessage
</script>
</head>
<body>
<div data-role="page" id="page">
<div data-role="content">
<form>
<div class="ui-body ui-body-b">
<div data-role="fieldcontain">
<center><h3>JPushPlugin Example</h3></center>
<span name="alias" id="alias"></span><hr />
<label>RegistrationID: </label>
<label id="registrationid">null</label>
</div>
<div data-role="fieldcontain">
<label>Tags: </label>
<table>
<tr>
<td>
<input type="text" id="tagText1"/>
</td>
</tr>
<tr>
<td>
<input type="text" id="tagText2"/>
</td>
</tr>
<tr>
<td>
<input type="text" id="tagText3">
</td>
</tr>
</table>
<label>Alias: </label>
<table>
<tr>
<td>
<input type="text" id="aliasText">
</td>
</tr>
</table>
</div>
<div data-role="fieldcontain">
<input type="button" id="setTagWithAliasButton" value="Add tag and alias" />
</div>
<div data-role="fieldcontain">
<label id="tagAliasPrompt" >设置tag/alias结果 </label>
<label id="tagAliasResult" >null</label>
</div>
<div data-role="fieldcontain">
<label id="notificationPrompt" >接受的通知内容:</label>
<label id="notificationResult" >null</label>
</div>
<div data-role="fieldcontain">
<label id="messagePrompt" >接受的自定义消息:</label>
<label id="messageResult" >null</label>
</div>
//jpush.receiveMessage
</script>
</head>
<body>
<div data-role="page" id="page">
<div data-role="content">
<form>
<div class="ui-body ui-body-b">
<div data-role="fieldcontain">
<center><h3>JPushPlugin Example</h3></center>
<span name="alias" id="alias"></span>
<hr/>
<label>RegistrationID: </label>
<label id="registrationid">null</label>
</div>
<div data-role="fieldcontain">
<label>Tags: </label>
<table>
<tr>
<td>
<input type="text" id="tagText1"/>
</td>
</tr>
<tr>
<td>
<input type="text" id="tagText2"/>
</td>
</tr>
<tr>
<td>
<input type="text" id="tagText3">
</td>
</tr>
</table>
<label>Alias: </label>
<table>
<tr>
<td>
<input type="text" id="aliasText">
</td>
</tr>
</table>
</div>
<div data-role="fieldcontain">
<input type="button" id="setTagWithAliasButton" value="Add tag and alias"/>
</div>
<div data-role="fieldcontain">
<label id="tagAliasPrompt">设置tag/alias结果 </label>
<label id="tagAliasResult">null</label>
</div>
<div data-role="fieldcontain">
<label id="notificationPrompt">接受的通知内容:</label>
<label id="notificationResult">null</label>
</div>
<div data-role="fieldcontain">
<label id="messagePrompt">接受的自定义消息:</label>
<label id="messageResult">null</label>
</div>
</div>
</form>
</div>
</div>
</body>
</form>
</div>
</div>
</body>
</html>

View File

@@ -2,7 +2,7 @@
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
xmlns:android="http://schemas.android.com/apk/res/android"
id="cn.jpush.phonegap.JPushPlugin"
version="2.0.2">
version="2.1.0">
<name>JPush Plugin</name>
<description>JPush for cordova plugin</description>
@@ -30,8 +30,8 @@
<header-file src="src/ios/Plugins/JPushPlugin.h"/>
<source-file src="src/ios/Plugins/JPushPlugin.m"/>
<header-file src="src/ios/lib/APService.h" />
<source-file src="src/ios/lib/libPushSDK-1.8.8.a" framework="true" />
<header-file src="src/ios/lib/JPUSHService.h" />
<source-file src="src/ios/lib/jpush-ios-2.1.0.a" framework="true" />
<header-file src="src/ios/Plugins/AppDelegate+JPush.h"/>
<source-file src="src/ios/Plugins/AppDelegate+JPush.m"/>
<resource-file src="src/ios/PushConfig.plist" />
@@ -163,10 +163,10 @@
<meta-data android:name="JPUSH_CHANNEL" android:value="developer-default"/>
<meta-data android:name="JPUSH_APPKEY" android:value="$API_KEY"/>
</config-file>
<source-file src="src/android/jpush-android-2.0.5.jar" target-dir="libs"/>
<source-file src="src/android/armeabi/libjpush205.so" target-dir="libs/armeabi"/>
<source-file src="src/android/armeabi-v7a/libjpush205.so" target-dir="libs/armeabi-v7a"/>
<source-file src="src/android/arm64-v8a/libjpush205.so" target-dir="libs/arm64-v8a"/>
<source-file src="src/android/jpush-android-2.0.6.jar" target-dir="libs"/>
<source-file src="src/android/armeabi/libjpush206.so" target-dir="libs/armeabi"/>
<source-file src="src/android/armeabi-v7a/libjpush206.so" target-dir="libs/armeabi-v7a"/>
<source-file src="src/android/arm64-v8a/libjpush206.so" target-dir="libs/arm64-v8a"/>
<!--<source-file src="src/android/JPushPlugin.java" target-dir="src/cn/jpush/phonegap"/>-->
<source-file src="src/android/MyReceiver.java" target-dir="src/cn/jpush/phonegap"/>

View File

@@ -26,6 +26,8 @@ import cn.jpush.android.api.CustomPushNotificationBuilder;
import cn.jpush.android.api.JPushInterface;
import cn.jpush.android.data.JPushLocalNotification;
import cn.jpush.android.api.TagAliasCallback;
import android.util.Log;
public class JPushPlugin extends CordovaPlugin {
private final static List<String> methodList =
@@ -33,7 +35,7 @@ public class JPushPlugin extends CordovaPlugin {
"getRegistrationID",
"setTags",
"setTagsWithAlias",
"setAlias",
"setAlias",
"getNotification",
"setBasicPushNotificationBuilder",
"setCustomPushNotificationBuilder",
@@ -46,7 +48,7 @@ public class JPushPlugin extends CordovaPlugin {
"setLatestNotificationNum",
"setPushTime",
"clearAllNotification",
"clearNotificationById",
"clearNotificationById",
"addLocalNotification",
"removeLocalNotification",
"clearLocalNotifications",
@@ -56,12 +58,16 @@ public class JPushPlugin extends CordovaPlugin {
private ExecutorService threadPool = Executors.newFixedThreadPool(1);
private static JPushPlugin instance;
private static String TAG = "JPushPlugin";
private static boolean shouldCacheMsg = false;
public static String notificationAlert;
public static Map<String, Object> notificationExtras=new HashMap<String, Object>();
public static String openNotificationAlert;
public static Map<String, Object> openNotificationExtras=new HashMap<String, Object>();
public JPushPlugin() {
instance = this;
}
@@ -69,21 +75,46 @@ public class JPushPlugin extends CordovaPlugin {
@Override
public void initialize(CordovaInterface cordova, CordovaWebView webView) {
super.initialize(cordova, webView);
//JPushInterface.setDebugMode(true);
//JPushPlugin.notificationAlert = alert;
//JPushPlugin.notificationExtras = extras;
if(JPushPlugin.openNotificationAlert != null){
JPushPlugin.transmitOpen(JPushPlugin.openNotificationAlert, JPushPlugin.openNotificationExtras);
}
if(JPushPlugin.notificationAlert!=null){
JPushPlugin.transmitReceive(JPushPlugin.notificationAlert, JPushPlugin.notificationExtras);
}
Log.i(TAG, "---------------- initialize"+"-"+JPushPlugin.openNotificationAlert + "-" + JPushPlugin.notificationAlert);
shouldCacheMsg = false;
//如果同时缓存了打开事件openNotificationAlert 和 消息事件notificationAlert只向UI 发 打开事件。
//这样做是为了和iOS 统一
if(JPushPlugin.openNotificationAlert != null){
JPushPlugin.notificationAlert = null;
JPushPlugin.transmitOpen(JPushPlugin.openNotificationAlert, JPushPlugin.openNotificationExtras);
}
if(JPushPlugin.notificationAlert!=null){
JPushPlugin.transmitReceive(JPushPlugin.notificationAlert, JPushPlugin.notificationExtras);
}
//JPushInterface.init(cordova.getActivity().getApplicationContext());
}
public void onPause(boolean multitasking) {
Log.i(TAG, "---------------- onPause");
shouldCacheMsg = true;
}
public void onResume(boolean multitasking) {
shouldCacheMsg = false;
Log.i(TAG, "---------------- onResume"+"-"+JPushPlugin.openNotificationAlert + "-" + JPushPlugin.notificationAlert);
if(JPushPlugin.openNotificationAlert != null){
JPushPlugin.notificationAlert = null;
JPushPlugin.transmitOpen(JPushPlugin.openNotificationAlert, JPushPlugin.openNotificationExtras);
}
if(JPushPlugin.notificationAlert!=null){
JPushPlugin.transmitReceive(JPushPlugin.notificationAlert, JPushPlugin.notificationExtras);
}
}
private static JSONObject notificationObject(String message,
Map<String, Object> extras) {
JSONObject data = new JSONObject();
@@ -158,19 +189,18 @@ public class JPushPlugin extends CordovaPlugin {
if (instance == null) {
return;
}
if(JPushPlugin.shouldCacheMsg){
return;
}
Log.i(TAG, "---------------- transmitOpen");
JSONObject data = openNotificationObject(alert, extras);
String js = String
.format("window.plugins.jPushPlugin.openNotificationInAndroidCallback('%s');",
data.toString());
// {"alert":"ding",
// "extras":{
// "cn.jpush.android.MSG_ID":"1691785879",
// "app":"com.thi.pushtest",
// "cn.jpush.android.ALERT":"ding",
// "cn.jpush.android.EXTRA":{},
// "cn.jpush.android.PUSH_ID":"1691785879",
// "cn.jpush.android.NOTIFICATION_ID":1691785879,
// "cn.jpush.android.NOTIFICATION_TYPE":"0"}}
try {
instance.webView.sendJavascript(js);
@@ -183,24 +213,22 @@ public class JPushPlugin extends CordovaPlugin {
} catch (Exception e) {
}
JPushPlugin.openNotificationAlert = null;
}
static void transmitReceive(String alert, Map<String, Object> extras) {
if (instance == null) {
return;
}
if(JPushPlugin.shouldCacheMsg){
return;
}
JSONObject data = openNotificationObject(alert, extras);
String js = String
.format("window.plugins.jPushPlugin.receiveNotificationInAndroidCallback('%s');",
data.toString());
// {"alert":"ding",
// "extras":{
// "cn.jpush.android.MSG_ID":"1691785879",
// "app":"com.thi.pushtest",
// "cn.jpush.android.ALERT":"ding",
// "cn.jpush.android.EXTRA":{},
// "cn.jpush.android.PUSH_ID":"1691785879",
// "cn.jpush.android.NOTIFICATION_ID":1691785879,
// "cn.jpush.android.NOTIFICATION_TYPE":"0"}}
try {
instance.webView.sendJavascript(js);
@@ -210,6 +238,8 @@ public class JPushPlugin extends CordovaPlugin {
} catch (Exception e) {
}
JPushPlugin.notificationAlert = null;
}
@Override
@@ -226,7 +256,7 @@ public class JPushPlugin extends CordovaPlugin {
JSONArray.class, CallbackContext.class);
method.invoke(JPushPlugin.this, data, callbackContext);
} catch (Exception e) {
System.out.println(e.toString());
Log.e(TAG,e.toString());
}
}
});
@@ -342,27 +372,15 @@ public class JPushPlugin extends CordovaPlugin {
}
void setTags(JSONArray data, CallbackContext callbackContext) {
HashSet<String> tags=null;
try {
String tagStr;
if(data==null){
//tags=null;
}else if(data.length()==0) {
tags= new HashSet<String>();
}else{
tagStr = data.getString(0);
String[] tagArray = tagStr.split(",");
for (String tag : tagArray) {
if(tags==null){
tags= new HashSet<String>();
}
tags.add(tag);
}
HashSet<String> tags=new HashSet<String>();
for(int i=0;i<data.length();i++){
tags.add(data.getString(i));
}
//Set<String> validTags = JPushInterface.filterValidTags(tags);
JPushInterface.setTags(this.cordova.getActivity()
.getApplicationContext(), tags,mTagWithAliasCallback);
callbackContext.success();
} catch (JSONException e) {
e.printStackTrace();
callbackContext.error("Error reading tags JSON");

View File

@@ -12,7 +12,7 @@ import android.content.Intent;
import android.util.Log;
public class MyReceiver extends BroadcastReceiver {
private static String TAG = "Client Receiver";
private static String TAG = "JPushPlugin";
@Override
public void onReceive(Context context, Intent intent) {
@@ -42,13 +42,14 @@ public class MyReceiver extends BroadcastReceiver {
JPushPlugin.transmitPush(msg, extras);
}
private void handlingNotificationOpen(Context context,Intent intent){
Log.i(TAG, "---------------- handlingNotificationOpen");
String alert = intent.getStringExtra(JPushInterface.EXTRA_ALERT);
Map<String,Object> extras = getNotificationExtras(intent);
Intent launch = context.getPackageManager().getLaunchIntentForPackage(context.getPackageName());
launch.addCategory(Intent.CATEGORY_LAUNCHER);
launch.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK|Intent.FLAG_ACTIVITY_SINGLE_TOP);
JPushPlugin.openNotificationAlert = alert;
JPushPlugin.openNotificationExtras = extras;
@@ -57,6 +58,9 @@ public class MyReceiver extends BroadcastReceiver {
context.startActivity(launch);
}
private void handlingNotificationReceive(Context context,Intent intent){
Log.i(TAG, "---------------- handlingNotificationReceive");
String alert = intent.getStringExtra(JPushInterface.EXTRA_ALERT);
Map<String,Object> extras = getNotificationExtras(intent);

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -9,9 +9,9 @@
#import "AppDelegate+JPush.h"
#import <objc/runtime.h>
#import "JPushPlugin.h"
#import "APService.h"
#import "JPUSHService.h"
static char launchNotificationKey;
//static char launchNotificationKey;
@implementation AppDelegate (JPush)
@@ -41,25 +41,44 @@ static char launchNotificationKey;
}
}
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
[APService registerDeviceToken:deviceToken];
[JPUSHService registerDeviceToken:deviceToken];
}
-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo{
[APService handleRemoteNotification:userInfo];
[JPUSHService handleRemoteNotification:userInfo];
[[NSNotificationCenter defaultCenter] postNotificationName:kJPushPluginReceiveNotification
object:userInfo];
}
-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler{
[APService handleRemoteNotification:userInfo];
[JPUSHService handleRemoteNotification:userInfo];
[[NSNotificationCenter defaultCenter] postNotificationName:kJPushPluginReceiveNotification
object:userInfo];
completionHandler(UIBackgroundFetchResultNewData);
}
- (void)application:(UIApplication *)application
didReceiveLocalNotification:(UILocalNotification *)notification {
[JPUSHService showLocalNotificationAtFront:notification identifierKey:nil];
}
- (void)applicationWillEnterForeground:(UIApplication *)application {
// [application setApplicationIconBadgeNumber:0];
// [application cancelAllLocalNotifications];
}
- (void)applicationDidEnterBackground:(UIApplication *)application {
// [[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];
}
//delegate
//-(NSDictionary *)luanchOption{
// return objc_getAssociatedObject(self, &launchNotificationKey);

View File

@@ -22,4 +22,17 @@
-(void)startLogPageView:(CDVInvokedUrlCommand*)command;
-(void)stopLogPageView:(CDVInvokedUrlCommand*)command;
// 设置角标到服务器, 服务器下一次发消息时,会设置成这个值
//本接口不会改变应用本地的角标值.
-(void)setBadge:(CDVInvokedUrlCommand*)command;
//相当于 [setBadge:0]
-(void)resetBadge:(CDVInvokedUrlCommand*)command;
//改变应用本地的角标值.
-(void)setApplicationIconBadgeNumber:(CDVInvokedUrlCommand*)command;
//获取应用本地的角标值.
-(void)getApplicationIconBadgeNumber:(CDVInvokedUrlCommand*)command;
@end

View File

@@ -7,335 +7,454 @@
//
#import "JPushPlugin.h"
#import "APService.h"
#import "JPUSHService.h"
#import <UIKit/UIKit.h>
static NSString *const JM_APP_KEY = @"APP_KEY";
static NSString *const JM_APP_CHANNEL = @"CHANNEL";
static NSString *const JM_APP_ISPRODUCTION = @"IsProduction";
static NSString *const JMessageConfigFileName = @"PushConfig";
static NSDictionary *_luanchOptions=nil;
@implementation JPushPlugin
+(void)setLaunchOptions:(NSDictionary *)theLaunchOptions{
_luanchOptions=theLaunchOptions;
[APService registerForRemoteNotificationTypes:(UIUserNotificationTypeBadge |
UIUserNotificationTypeSound |
UIUserNotificationTypeAlert)
categories:nil];
[APService setupWithOption:_luanchOptions];
_luanchOptions=theLaunchOptions;
[JPUSHService setDebugMode];
if ([[UIDevice currentDevice].systemVersion floatValue] >= 8.0) {
//categories
[JPUSHService registerForRemoteNotificationTypes:(UIUserNotificationTypeBadge |
UIUserNotificationTypeSound |
UIUserNotificationTypeAlert)
categories:nil];
} else {
//categories nil
[JPUSHService registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge |
UIRemoteNotificationTypeSound |
UIRemoteNotificationTypeAlert)
categories:nil];
}
//read appkey and channel from JMessageConfig.plist
NSString *plistPath = [[NSBundle mainBundle] pathForResource:JMessageConfigFileName ofType:@"plist"];
if (plistPath == nil) {
NSLog(@"error: PushConfig.plist not found");
assert(0);
}
NSMutableDictionary *plistData = [[NSMutableDictionary alloc] initWithContentsOfFile:plistPath];
NSString * appkey = [plistData valueForKey:JM_APP_KEY];
NSString * channel = [plistData valueForKey:JM_APP_CHANNEL];
NSNumber * isProduction = [plistData valueForKey:JM_APP_ISPRODUCTION];
if (!appkey || appkey.length == 0) {
NSLog(@"error: app key not found in JMessageConfig.plist ");
assert(0);
}
[JPUSHService setupWithOption:_luanchOptions appKey:appkey
channel:channel apsForProduction:[isProduction boolValue] ];
}
-(void)initial:(CDVInvokedUrlCommand*)command{
//do nithng,because Cordova plugin use lazy load mode.
}
- (CDVPlugin*)initWithWebView:(UIWebView*)theWebView{
if (self=[super initWithWebView:theWebView]) {
NSNotificationCenter *defaultCenter = [NSNotificationCenter defaultCenter];
[defaultCenter addObserver:self
selector:@selector(networkDidReceiveMessage:)
name:kJPFNetworkDidReceiveMessageNotification
object:nil];
[defaultCenter addObserver:self
selector:@selector(networkDidReceiveNotification:)
name:kJPushPluginReceiveNotification
object:nil];
if (_luanchOptions) {
NSDictionary *userInfo = [_luanchOptions
valueForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
if ([userInfo count] >0) {
NSError *error;
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:userInfo options:0 error:&error];
NSString *jsonString = [[NSString alloc]initWithData:jsonData encoding:NSUTF8StringEncoding];
if (!error) {
dispatch_async(dispatch_get_main_queue(), ^{
[self.commandDelegate evalJs:[NSString stringWithFormat:@"cordova.fireDocumentEvent('jpush.openNotification',%@)",jsonString]];
});
}
}
}
}
return self;
-(void)stopPush:(CDVInvokedUrlCommand*)command{
[[UIApplication sharedApplication]unregisterForRemoteNotifications];
}
-(void)setTagsWithAlias:(CDVInvokedUrlCommand*)command{
NSArray *arguments=command.arguments;
if (!arguments||[arguments count]<2) {
// [self writeJavascript:[NSString stringWithFormat:@"window.plugins.jPushPlugin.pushCallback('%@')",@""]];
return ;
}
NSString *alias=[arguments objectAtIndex:0];
NSArray *arrayTags=[arguments objectAtIndex:1];
NSSet* set=[NSSet setWithArray:arrayTags];
[APService setTags:set
alias:alias
callbackSelector:@selector(tagsWithAliasCallback:tags:alias:)
object:self];
}
-(void)resumePush:(CDVInvokedUrlCommand*)command{
#if __IPHONE_OS_VERSION_MAX_ALLOWED > __IPHONE_7_1
if ([[UIDevice currentDevice].systemVersion floatValue] >= 8.0) {
if ([[UIDevice currentDevice].systemVersion floatValue] >= 8.0) {
//categories
[APService registerForRemoteNotificationTypes:(UIUserNotificationTypeBadge |
UIUserNotificationTypeSound |
UIUserNotificationTypeAlert)
categories:nil];
} else {
//categories nil
[APService registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge |
UIRemoteNotificationTypeSound |
UIRemoteNotificationTypeAlert)
categories:nil];
}
#else
[JPUSHService registerForRemoteNotificationTypes:(UIUserNotificationTypeBadge |
UIUserNotificationTypeSound |
UIUserNotificationTypeAlert)
categories:nil];
} else {
//categories nil
[APService registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge |
UIRemoteNotificationTypeSound |
UIRemoteNotificationTypeAlert)
categories:nil];
[JPUSHService registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge |
UIRemoteNotificationTypeSound |
UIRemoteNotificationTypeAlert)
categories:nil];
}
#else
//categories nil
[JPUSHService registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge |
UIRemoteNotificationTypeSound |
UIRemoteNotificationTypeAlert)
categories:nil];
#endif
}
-(void)isPushStopped:(CDVInvokedUrlCommand*)command{
NSNumber *result;
if ([[UIApplication sharedApplication] isRegisteredForRemoteNotifications ]) {
result=@(0);
}else{
result=@(1);
}
CDVPluginResult * pushResult=[self pluginResultForValue:result];
if (pushResult) {
[self succeedWithPluginResult:pushResult withCallbackID:command.callbackId];
} else {
[self failWithCallbackID:command.callbackId];
}
}
-(void)initial:(CDVInvokedUrlCommand*)command{
//do nithng,because Cordova plugin use lazy load mode.
}
#ifdef __CORDOVA_4_0_0
- (void)pluginInitialize {
NSLog(@"### pluginInitialize ");
[self initNotifications];
}
#else
- (CDVPlugin*)initWithWebView:(UIWebView*)theWebView{
NSLog(@"### initWithWebView ");
if (self=[super initWithWebView:theWebView]) {
[self initNotifications];
}
return self;
}
#endif
}
-(void)isPushStopped:(CDVInvokedUrlCommand*)command{
NSNumber *result;
if ([[UIApplication sharedApplication] isRegisteredForRemoteNotifications ]) {
result=@(0);
}else{
result=@(1);
-(void)initNotifications {
NSNotificationCenter *defaultCenter = [NSNotificationCenter defaultCenter];
[defaultCenter addObserver:self
selector:@selector(networkDidReceiveMessage:)
name:kJPFNetworkDidReceiveMessageNotification
object:nil];
[defaultCenter addObserver:self
selector:@selector(networkDidReceiveNotification:)
name:kJPushPluginReceiveNotification
object:nil];
if (_luanchOptions) {
NSDictionary *userInfo = [_luanchOptions
valueForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
if ([userInfo count] >0) {
NSError *error;
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:userInfo options:0 error:&error];
NSString *jsonString = [[NSString alloc]initWithData:jsonData encoding:NSUTF8StringEncoding];
if (!error) {
dispatch_async(dispatch_get_main_queue(), ^{
[self.commandDelegate evalJs:[NSString stringWithFormat:@"cordova.fireDocumentEvent('jpush.openNotification',%@)",jsonString]];
});
}
}
CDVPluginResult * pushResult=[self pluginResultForValue:result];
if (pushResult) {
[self succeedWithPluginResult:pushResult withCallbackID:command.callbackId];
} else {
[self failWithCallbackID:command.callbackId];
}}
-(void)setTags:(CDVInvokedUrlCommand *)command{
}
}
NSArray *arguments=[command arguments];
NSString *tags=[arguments objectAtIndex:0];
NSArray *array=[tags componentsSeparatedByString:@","];
[APService setTags:[NSSet setWithArray:array]
callbackSelector:@selector(tagsWithAliasCallback:tags:alias:)
object:self];
-(void)setTagsWithAlias:(CDVInvokedUrlCommand*)command{
NSArray *arguments=command.arguments;
if (!arguments||[arguments count]<2) {
NSLog(@"#### setTagsWithAlias param is less");
return ;
}
NSString *alias=[arguments objectAtIndex:0];
NSArray *arrayTags=[arguments objectAtIndex:1];
NSLog(@"#### setTagsWithAlias alias is %@, tags is %@",alias,arrayTags);
NSSet* set=[NSSet setWithArray:arrayTags];
[JPUSHService setTags:set
alias:alias
callbackSelector:@selector(tagsWithAliasCallback:tags:alias:)
object:self];
}
-(void)setTags:(CDVInvokedUrlCommand *)command{
NSArray *arguments=[command arguments];
NSString *tags=[arguments objectAtIndex:0];
NSLog(@"#### setTags %@",tags);
NSArray *array=[tags componentsSeparatedByString:@","];
[JPUSHService setTags:[NSSet setWithArray:array]
callbackSelector:@selector(tagsWithAliasCallback:tags:alias:)
object:self];
}
-(void)setAlias:(CDVInvokedUrlCommand *)command{
NSArray *arguments=[command arguments];
[APService setAlias:[arguments objectAtIndex:0]
callbackSelector:@selector(tagsWithAliasCallback:tags:alias:)
object:self];
NSArray *arguments=[command arguments];
NSLog(@"#### setAlias %@",arguments);
[JPUSHService setAlias:[arguments objectAtIndex:0]
callbackSelector:@selector(tagsWithAliasCallback:tags:alias:)
object:self];
}
-(void)getRegistrationID:(CDVInvokedUrlCommand*)command{
NSString* registrationID = [APService registrationID];
CDVPluginResult *result=[self pluginResultForValue:registrationID];
if (result) {
[self succeedWithPluginResult:result withCallbackID:command.callbackId];
} else {
[self failWithCallbackID:command.callbackId];
}
NSString* registrationID = [JPUSHService registrationID];
NSLog(@"### getRegistrationID %@",registrationID);
CDVPluginResult *result=[self pluginResultForValue:registrationID];
if (result) {
[self succeedWithPluginResult:result withCallbackID:command.callbackId];
} else {
[self failWithCallbackID:command.callbackId];
}
}
-(void)tagsWithAliasCallback:(int)resultCode tags:(NSSet *)tags alias:(NSString *)alias{
NSDictionary *dict=[NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithInt:resultCode],@"resultCode",
tags==nil?[NSNull null]:[tags allObjects],@"tags",
alias==nil?[NSNull null]:alias,@"alias",nil];
NSMutableDictionary *data = [NSMutableDictionary dictionary];
[data setObject:[NSNumber numberWithInt:resultCode] forKey:@"resultCode"];
[data setObject:tags==nil?[NSNull null]:[tags allObjects] forKey:@"tags"];
[data setObject:alias==nil?[NSNull null]:alias forKey:@"alias"];
NSError *error;
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:dict options:0 error:&error];
NSString *jsonString = [[NSString alloc]initWithData:jsonData encoding:NSUTF8StringEncoding];
dispatch_async(dispatch_get_main_queue(), ^{
[self.commandDelegate evalJs:[NSString stringWithFormat:@"cordova.fireDocumentEvent('jpush.setTagsWithAlias',%@)",jsonString]];
// [self writeJavascript:[NSString stringWithFormat:@"window.plugins.jPushPlugin.pushCallback('%@')",jsonString]];
});
NSDictionary *dict=[NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithInt:resultCode],@"resultCode",
tags==nil?[NSNull null]:[tags allObjects],@"tags",
alias==nil?[NSNull null]:alias,@"alias",nil];
NSMutableDictionary *data = [NSMutableDictionary dictionary];
[data setObject:[NSNumber numberWithInt:resultCode] forKey:@"resultCode"];
[data setObject:tags==nil?[NSNull null]:[tags allObjects] forKey:@"tags"];
[data setObject:alias==nil?[NSNull null]:alias forKey:@"alias"];
NSError *error;
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:dict options:0 error:&error];
NSString *jsonString = [[NSString alloc]initWithData:jsonData encoding:NSUTF8StringEncoding];
dispatch_async(dispatch_get_main_queue(), ^{
[self.commandDelegate evalJs:[NSString stringWithFormat:@"cordova.fireDocumentEvent('jpush.setTagsWithAlias',%@)",jsonString]];
// [self writeJavascript:[NSString stringWithFormat:@"window.plugins.jPushPlugin.pushCallback('%@')",jsonString]];
});
}
-(void)startLogPageView:(CDVInvokedUrlCommand*)command{
NSArray *arguments=command.arguments;
if (!arguments||[arguments count]<1) {
NSLog(@"startLogPageView argument error");
return ;
}
NSString * pageName=[arguments objectAtIndex:0];
if (pageName) {
[APService startLogPageView:pageName];
}
NSArray *arguments=command.arguments;
if (!arguments||[arguments count]<1) {
NSLog(@"startLogPageView argument error");
return ;
}
NSString * pageName=[arguments objectAtIndex:0];
if (pageName) {
[JPUSHService startLogPageView:pageName];
}
}
-(void)stopLogPageView:(CDVInvokedUrlCommand*)command{
NSArray *arguments=command.arguments;
if (!arguments||[arguments count]<1) {
NSLog(@"stopLogPageView argument error");
return ;
}
NSString * pageName=[arguments objectAtIndex:0];
if (pageName) {
[APService stopLogPageView:pageName];
}
NSArray *arguments=command.arguments;
if (!arguments||[arguments count]<1) {
NSLog(@"stopLogPageView argument error");
return ;
}
NSString * pageName=[arguments objectAtIndex:0];
if (pageName) {
[JPUSHService stopLogPageView:pageName];
}
}
-(void)beginLogPageView:(CDVInvokedUrlCommand*)command{
NSArray *arguments=command.arguments;
if (!arguments||[arguments count]<2) {
NSLog(@"beginLogPageView argument error");
return ;
}
NSString * pageName=[arguments objectAtIndex:0];
int duration=[[arguments objectAtIndex:0]intValue];
if (pageName) {
[APService beginLogPageView:pageName duration:duration];
}
NSArray *arguments=command.arguments;
if (!arguments||[arguments count]<2) {
NSLog(@"beginLogPageView argument error");
return ;
}
NSString * pageName=[arguments objectAtIndex:0];
int duration=[[arguments objectAtIndex:0]intValue];
if (pageName) {
[JPUSHService beginLogPageView:pageName duration:duration];
}
}
-(void)setBadge:(CDVInvokedUrlCommand*)command{
NSArray *argument=command.arguments;
if ([argument count]<1) {
NSLog(@"setBadge argument error!");
return;
}
NSNumber *badge=[argument objectAtIndex:0];
[APService setBadge:[badge intValue]];
NSArray *argument=command.arguments;
if ([argument count]<1) {
NSLog(@"setBadge argument error!");
return;
}
NSNumber *badge=[argument objectAtIndex:0];
[JPUSHService setBadge:[badge intValue]];
}
-(void)resetBadge:(CDVInvokedUrlCommand*)command{
[APService resetBadge];
}
-(void)setDebugModeFromIos:(CDVInvokedUrlCommand*)command{
[APService setDebugMode];
}
-(void)setLogOFF:(CDVInvokedUrlCommand*)command{
[APService setLogOFF];
}
-(void)stopPush:(CDVInvokedUrlCommand*)command{
[[UIApplication sharedApplication]unregisterForRemoteNotifications];
-(void)resetBadge:(CDVInvokedUrlCommand*)command{
[JPUSHService resetBadge];
}
-(void)setApplicationIconBadgeNumber:(CDVInvokedUrlCommand *)command{
//
NSArray *argument=command.arguments;
if ([argument count]<1) {
NSLog(@"setBadge argument error!");
return;
}
NSNumber *badge=[argument objectAtIndex:0];
[UIApplication sharedApplication].applicationIconBadgeNumber=[badge intValue];
}
-(void)getApplicationIconBadgeNumber:(CDVInvokedUrlCommand *)command {
NSInteger num = [UIApplication sharedApplication].applicationIconBadgeNumber;
CDVPluginResult *result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsInt:num];
[self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
}
-(void)setDebugModeFromIos:(CDVInvokedUrlCommand*)command{
[JPUSHService setDebugMode];
}
-(void)setLogOFF:(CDVInvokedUrlCommand*)command{
[JPUSHService setLogOFF];
}
- (void)failWithCallbackID:(NSString *)callbackID {
CDVPluginResult *result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR];
[self.commandDelegate sendPluginResult:result callbackId:callbackID];
CDVPluginResult *result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR];
[self.commandDelegate sendPluginResult:result callbackId:callbackID];
}
- (void)succeedWithPluginResult:(CDVPluginResult *)result withCallbackID:(NSString *)callbackID {
[self.commandDelegate sendPluginResult:result callbackId:callbackID];
}
-(void)setApplicationIconBadgeNumber:(CDVInvokedUrlCommand*)command{
//
NSArray *argument=command.arguments;
if ([argument count]<1) {
NSLog(@"setBadge argument error!");
return;
}
NSNumber *badge=[argument objectAtIndex:0];
[UIApplication sharedApplication].applicationIconBadgeNumber=[badge intValue];
[self.commandDelegate sendPluginResult:result callbackId:callbackID];
}
- (CDVPluginResult *)pluginResultForValue:(id)value {
CDVPluginResult *result;
if ([value isKindOfClass:[NSString class]]) {
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK
messageAsString:[value stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
} else if ([value isKindOfClass:[NSNumber class]]) {
CFNumberType numberType = CFNumberGetType((CFNumberRef)value);
//note: underlyingly, BOOL values are typedefed as char
if (numberType == kCFNumberIntType || numberType == kCFNumberCharType) {
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsInt:[value intValue]];
} else {
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDouble:[value doubleValue]];
}
} else if ([value isKindOfClass:[NSArray class]]) {
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsArray:value];
} else if ([value isKindOfClass:[NSDictionary class]]) {
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:value];
} else if ([value isKindOfClass:[NSNull class]]) {
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
} else {
NSLog(@"Cordova callback block returned unrecognized type: %@", NSStringFromClass([value class]));
return nil;
CDVPluginResult *result;
if ([value isKindOfClass:[NSString class]]) {
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK
messageAsString:[value stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
} else if ([value isKindOfClass:[NSNumber class]]) {
CFNumberType numberType = CFNumberGetType((CFNumberRef)value);
//note: underlyingly, BOOL values are typedefed as char
if (numberType == kCFNumberIntType || numberType == kCFNumberCharType) {
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsInt:[value intValue]];
} else {
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDouble:[value doubleValue]];
}
return result;
} else if ([value isKindOfClass:[NSArray class]]) {
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsArray:value];
} else if ([value isKindOfClass:[NSDictionary class]]) {
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:value];
} else if ([value isKindOfClass:[NSNull class]]) {
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
} else {
NSLog(@"Cordova callback block returned unrecognized type: %@", NSStringFromClass([value class]));
return nil;
}
return result;
}
- (void)networkDidReceiveMessage:(NSNotification *)notification {
NSDictionary *userInfo = [notification userInfo];
//NSLog(@"%@",userInfo);
NSDictionary *userInfo = [notification userInfo];
//NSLog(@"%@",userInfo);
NSError *error;
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:userInfo options:0 error:&error];
NSString *jsonString = [[NSString alloc]initWithData:jsonData encoding:NSUTF8StringEncoding];
//NSLog(@"%@",jsonString);
dispatch_async(dispatch_get_main_queue(), ^{
NSError *error;
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:userInfo options:0 error:&error];
NSString *jsonString = [[NSString alloc]initWithData:jsonData encoding:NSUTF8StringEncoding];
//NSLog(@"%@",jsonString);
[self.commandDelegate evalJs:[NSString stringWithFormat:@"cordova.fireDocumentEvent('jpush.receiveMessage',%@)",jsonString]];
dispatch_async(dispatch_get_main_queue(), ^{
[self.commandDelegate evalJs:[NSString stringWithFormat:@"cordova.fireDocumentEvent('jpush.receiveMessage',%@)",jsonString]];
[self.commandDelegate evalJs:[NSString stringWithFormat:@"window.plugins.jPushPlugin.receiveMessageIniOSCallback('%@')",jsonString]];
});
[self.commandDelegate evalJs:[NSString stringWithFormat:@"window.plugins.jPushPlugin.receiveMessageIniOSCallback('%@')",jsonString]];
});
}
-(void)networkDidReceiveNotification:(id)notification{
NSError *error;
NSDictionary *userInfo = [notification object];
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:userInfo options:0 error:&error];
NSString *jsonString = [[NSString alloc]initWithData:jsonData encoding:NSUTF8StringEncoding];
switch ([UIApplication sharedApplication].applicationState) {
case UIApplicationStateActive:
{
dispatch_async(dispatch_get_main_queue(), ^{
[self.commandDelegate evalJs:[NSString stringWithFormat:@"cordova.fireDocumentEvent('jpush.receiveNotification',%@)",jsonString]];
});
}
break;
case UIApplicationStateInactive:
case UIApplicationStateBackground:
{
dispatch_async(dispatch_get_main_queue(), ^{
[self.commandDelegate evalJs:[NSString stringWithFormat:@"cordova.fireDocumentEvent('jpush.openNotification',%@)",jsonString]];
});
}
break;
default:
//do nothing
break;
NSError *error;
NSDictionary *userInfo = [notification object];
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:userInfo options:0 error:&error];
NSString *jsonString = [[NSString alloc]initWithData:jsonData encoding:NSUTF8StringEncoding];
switch ([UIApplication sharedApplication].applicationState) {
case UIApplicationStateActive:
{
dispatch_async(dispatch_get_main_queue(), ^{
[self.commandDelegate evalJs:[NSString stringWithFormat:@"cordova.fireDocumentEvent('jpush.receiveNotification',%@)",jsonString]];
});
}
break;
case UIApplicationStateInactive:
case UIApplicationStateBackground:
{
dispatch_async(dispatch_get_main_queue(), ^{
[self.commandDelegate evalJs:[NSString stringWithFormat:@"cordova.fireDocumentEvent('jpush.openNotification',%@)",jsonString]];
});
}
break;
default:
//do nothing
break;
}
}

View File

@@ -1,10 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>APP_KEY</key>
<string></string>
<key>CHANNEL</key>
<string>Subscription</string>
</dict>
<dict>
<key>APP_KEY</key>
<string></string>
<key>CHANNEL</key>
<string>Subscription</string>
<key>IsProduction</key>
<false/>
</dict>
</plist>

View File

@@ -1,175 +0,0 @@
//
// APService.h
// APService
//
// Created by JPush on 12-8-15.
// Copyright (c) 2012年 HXHG. All rights reserved.
// Version: 1.8.8
@class CLRegion;
@class UILocalNotification;
extern NSString *const kJPFNetworkDidSetupNotification; // 建立连接
extern NSString *const kJPFNetworkDidCloseNotification; // 关闭连接
extern NSString *const kJPFNetworkDidRegisterNotification; // 注册成功
extern NSString *const kJPFNetworkDidLoginNotification; // 登录成功
extern NSString *const
kJPFNetworkDidReceiveMessageNotification; // 收到消息(非APNS)
extern NSString *const kJPFServiceErrorNotification; // 错误提示
@class CLLocation;
@interface APService : NSObject
#pragma - mark 基本功能
// 以下四个接口是必须调用的
+ (void)setupWithOption:(NSDictionary *)launchingOption; // 初始化
+ (void)registerForRemoteNotificationTypes:(NSUInteger)types
categories:(NSSet *)categories; // 注册APNS类型
+ (void)registerDeviceToken:(NSData *)deviceToken; // 向服务器上报Device Token
+ (void)handleRemoteNotification:(NSDictionary *)
remoteInfo; // 处理收到的APNS消息向服务器上报收到APNS消息
// 下面的接口是可选的
// 设置标签和(或)别名若参数为nil则忽略若是空对象则清空详情请参考文档http://docs.jpush.cn/pages/viewpage.action?pageId=3309913
+ (void)setTags:(NSSet *)tags
alias:(NSString *)alias
callbackSelector:(SEL)cbSelector
target:(id)theTarget;
+ (void)setTags:(NSSet *)tags
alias:(NSString *)alias
callbackSelector:(SEL)cbSelector
object:(id)theTarget;
+ (void)setTags:(NSSet *)tags
callbackSelector:(SEL)cbSelector
object:(id)theTarget;
+ (void)setAlias:(NSString *)alias
callbackSelector:(SEL)cbSelector
object:(id)theTarget;
// 用于过滤出正确可用的tags如果总数量超出最大限制则返回最大数量的靠前的可用tags
+ (NSSet *)filterValidTags:(NSSet *)tags;
#pragma - mark 上报日志
/**
* 记录页面停留时间功能。
* startLogPageView和stopLogPageView为自动计算停留时间
* beginLogPageView为手动自己输入停留时间
*
* @param pageName 页面名称
* @param seconds 页面停留时间
*/
+ (void)startLogPageView:(NSString *)pageName;
+ (void)stopLogPageView:(NSString *)pageName;
+ (void)beginLogPageView:(NSString *)pageName duration:(int)seconds;
/**
* 开启Crash日志收集, 默认是关闭状态.
*/
+ (void)crashLogON;
/**
* 地理位置设置
* 为了更精确的统计用户地理位置,可以调用此方法传入经纬度信息
* 需要链接 CoreLocation.framework 并且 #import <CoreLocation/CoreLocation.h>
* @param latitude 纬度.
* @param longitude 经度.
* @param location 直接传递CLLocation *型的地理信息
*/
+ (void)setLatitude:(double)latitude longitude:(double)longitude;
+ (void)setLocation:(CLLocation *)location;
#pragma - mark 本地通知
/**
* 本地推送最多支持64个
* @param fireDate 本地推送触发的时间
* @param alertBody 本地推送需要显示的内容
* @param badge 角标的数字。如果不需要改变角标传-1
* @param alertAction 弹框的按钮显示的内容IOS 8默认为"打开",其他默认为"启动"
* @param notificationKey 本地推送标示符
* @param userInfo 自定义参数,可以用来标识推送和增加附加信息
* @param soundName 自定义通知声音设置为nil为默认声音
* IOS8新参数
* @param region 自定义参数
* @param regionTriggersOnce 自定义参数
* @param category 自定义参数
*/
+ (UILocalNotification *)setLocalNotification:(NSDate *)fireDate
alertBody:(NSString *)alertBody
badge:(int)badge
alertAction:(NSString *)alertAction
identifierKey:(NSString *)notificationKey
userInfo:(NSDictionary *)userInfo
soundName:(NSString *)soundName;
+ (UILocalNotification *)setLocalNotification:(NSDate *)fireDate
alertBody:(NSString *)alertBody
badge:(int)badge
alertAction:(NSString *)alertAction
identifierKey:(NSString *)notificationKey
userInfo:(NSDictionary *)userInfo
soundName:(NSString *)soundName
region:(CLRegion *)region
regionTriggersOnce:(BOOL)regionTriggersOnce
category:(NSString *)category
NS_AVAILABLE_IOS(8_0);
/**
* 本地推送在前台推送。默认App在前台运行时不会进行弹窗在程序接收通知调用此接口可实现指定的推送弹窗。
* @param notification 本地推送对象
* @param notificationKey 需要前台显示的本地推送通知的标示符
*/
+ (void)showLocalNotificationAtFront:(UILocalNotification *)notification
identifierKey:(NSString *)notificationKey;
/**
* 删除本地推送
* @param notificationKey 本地推送标示符
* @param myUILocalNotification 本地推送对象
*/
+ (void)deleteLocalNotificationWithIdentifierKey:(NSString *)notificationKey;
+ (void)deleteLocalNotification:(UILocalNotification *)localNotification;
/**
* 获取指定通知
* @param notificationKey 本地推送标示符
* @return 本地推送对象数组,[array count]为0时表示没找到
*/
+ (NSArray *)findLocalNotificationWithIdentifier:(NSString *)notificationKey;
/**
* 清除所有本地推送对象
*/
+ (void)clearAllLocalNotifications;
#pragma - mark 设置Badge
/**
* set setBadge
* @param value 设置JPush服务器的badge的值
* 本地仍须调用UIApplication:setApplicationIconBadgeNumber函数,来设置脚标
*/
+ (BOOL)setBadge:(NSInteger)value;
/**
* set setBadge
* @param value 清除JPush服务器对badge值的设定.
* 本地仍须调用UIApplication:setApplicationIconBadgeNumber函数,来设置脚标
*/
+ (void)resetBadge;
/**
* get RegistrationID
*/
+ (NSString *)registrationID;
#pragma - mark 打印日志信息配置
/**
* setDebugMode获取更多的Log信息
* 开发过程中建议开启DebugMode
*
* setLogOFF关闭除了错误信息外的所有Log
* 发布时建议开启LogOFF用于节省性能开销
*
* 默认为不开启DebugLog,只显示基本的信息
*/
+ (void)setDebugMode;
+ (void)setLogOFF;
@end

337
src/ios/lib/JPUSHService.h Executable file
View File

@@ -0,0 +1,337 @@
/*
* | | | | \ \ / / | | | | / _______|
* | |____| | \ \/ / | |____| | / /
* | |____| | \ / | |____| | | | _____
* | | | | / \ | | | | | | |____ |
* | | | | / /\ \ | | | | \ \______| |
* | | | | /_/ \_\ | | | | \_________|
*
* Copyright (c) 2011 ~ 2015 Shenzhen HXHG. All rights reserved.
*/
#define JPUSH_VERSION_NUMBER 2.1.0
#import <Foundation/Foundation.h>
@class CLRegion;
@class UILocalNotification;
extern NSString *const kJPFNetworkIsConnectingNotification; // 正在连接中
extern NSString *const kJPFNetworkDidSetupNotification; // 建立连接
extern NSString *const kJPFNetworkDidCloseNotification; // 关闭连接
extern NSString *const kJPFNetworkDidRegisterNotification; // 注册成功
extern NSString *const kJPFNetworkDidLoginNotification; // 登录成功
extern NSString *const kJPFNetworkDidReceiveMessageNotification; // 收到消息(非APNS)
extern NSString *const kJPFServiceErrorNotification; // 错误提示
@class CLLocation;
/*!
* JPush 核心头文件
*/
@interface JPUSHService : NSObject
///----------------------------------------------------
/// @name Setup 启动相关
///----------------------------------------------------
/*!
* @abstract 启动SDK
*
* @discussion 这是旧版本的启动方法, 依赖于 PushConfig.plist 文件. 建议不要使用, 已经过期.
*/
+ (void)setupWithOption:(NSDictionary *)launchingOption __attribute__((deprecated("JPush 2.1.0 版本已过期")));
/*!
* @abstract 启动SDK
*
* @param launchingOption 启动参数.
* @param appKey 一个JPush 应用必须的,唯一的标识. 请参考 JPush 相关说明文档来获取这个标识.
* @param channel 发布渠道. 可选.
* @param isProduction 是否生产环境. 如果为开发状态,设置为 NO; 如果为生产状态,应改为 YES.
*
* @discussion 提供SDK启动必须的参数, 来启动 SDK.
* 此接口必须在 App 启动时调用, 否则 JPush SDK 将无法正常工作.
*/
+ (void)setupWithOption:(NSDictionary *)launchingOption
appKey:(NSString *)appKey
channel:(NSString *)channel
apsForProduction:(BOOL)isProduction;
///----------------------------------------------------
/// @name APNs about 通知相关
///----------------------------------------------------
/*!
* @abstract 注册要处理的远程通知类型
*
* @param types 通知类型
* @param categories
*
* @discussion
*/
+ (void)registerForRemoteNotificationTypes:(NSUInteger)types
categories:(NSSet *)categories;
+ (void)registerDeviceToken:(NSData *)deviceToken;
/*!
* @abstract 处理收到的 APNs 消息
*/
+ (void)handleRemoteNotification:(NSDictionary *)remoteInfo;
///----------------------------------------------------
/// @name Tag alias setting 设置别名与标签
///----------------------------------------------------
/*!
* 下面的接口是可选的
* 设置标签和(或)别名若参数为nil则忽略若是空对象则清空详情请参考文档http://docs.jpush.io/client/ios_api/#api-ios
* setTags:alias:fetchCompletionHandle:是新的设置标签别名的方法不再需要显示声明回调函数只需要在block里面处理设置结果即可.
* WARN: 使用block时需要注意循环引用问题
*/
+ (void) setTags:(NSSet *)tags
alias:(NSString *)alias
callbackSelector:(SEL)cbSelector
target:(id)theTarget;
+ (void) setTags:(NSSet *)tags
alias:(NSString *)alias
callbackSelector:(SEL)cbSelector
object:(id)theTarget;
+ (void) setTags:(NSSet *)tags
callbackSelector:(SEL)cbSelector
object:(id)theTarget;
+ (void) setTags:(NSSet *)tags
alias:(NSString *)alias
fetchCompletionHandle:(void (^)(int iResCode, NSSet *iTags, NSString *iAlias))completionHandler;
+ (void) setTags:(NSSet *)tags
aliasInbackground:(NSString *)alias;
+ (void)setAlias:(NSString *)alias
callbackSelector:(SEL)cbSelector
object:(id)theTarget;
/*!
* @abstract 过滤掉无效的 tags
*
* @discussion 如果 tags 数量超过限制数量, 则返回靠前的有效的 tags.
* 建议设置 tags 前用此接口校验. SDK 内部也会基于此接口来做过滤.
*/
+ (NSSet *)filterValidTags:(NSSet *)tags;
///----------------------------------------------------
/// @name Stats 统计功能
///----------------------------------------------------
/*!
* @abstract 开始记录页面停留
*
* @param pageName 页面名称
*/
+ (void)startLogPageView:(NSString *)pageName;
/*!
* @abstract 停止记录页面停留
*
* @param pageName 页面
*/
+ (void)stopLogPageView:(NSString *)pageName;
/*!
* @abstract 直接上报在页面的停留时工
*
* @param pageName 页面
* @param seconds 停留的秒数
*/
+ (void)beginLogPageView:(NSString *)pageName duration:(int)seconds;
/*!
* @abstract 开启Crash日志收集
*
* @discussion 默认是关闭状态.
*/
+ (void)crashLogON;
/*!
* @abstract 地理位置上报
*
* @param latitude 纬度.
* @param longitude 经度.
*
*/
+ (void)setLatitude:(double)latitude longitude:(double)longitude;
/*!
* @abstract 地理位置上报
*
* @param location 直接传递 CLLocation * 型的地理信息
*
* @discussion 需要链接 CoreLocation.framework 并且 #import <CoreLocation/CoreLocation.h>
*/
+ (void)setLocation:(CLLocation *)location;
///----------------------------------------------------
/// @name Local Notification 本地通知
///----------------------------------------------------
/*!
* @abstract 本地推送最多支持64个
*
* @param fireDate 本地推送触发的时间
* @param alertBody 本地推送需要显示的内容
* @param badge 角标的数字。如果不需要改变角标传-1
* @param alertAction 弹框的按钮显示的内容IOS 8默认为"打开", 其他默认为"启动"
* @param notificationKey 本地推送标示符
* @param userInfo 自定义参数,可以用来标识推送和增加附加信息
* @param soundName 自定义通知声音设置为nil为默认声音
*
* @discussion 最多支持 64 个定义
*/
+ (UILocalNotification *)setLocalNotification:(NSDate *)fireDate
alertBody:(NSString *)alertBody
badge:(int)badge
alertAction:(NSString *)alertAction
identifierKey:(NSString *)notificationKey
userInfo:(NSDictionary *)userInfo
soundName:(NSString *)soundName;
/*!
* @abstract 本地推送 (支持 iOS8 新参数)
*
* IOS8新参数
* @param region 自定义参数
* @param regionTriggersOnce 自定义参数
* @param category 自定义参数
*/
+ (UILocalNotification *)setLocalNotification:(NSDate *)fireDate
alertBody:(NSString *)alertBody
badge:(int)badge
alertAction:(NSString *)alertAction
identifierKey:(NSString *)notificationKey
userInfo:(NSDictionary *)userInfo
soundName:(NSString *)soundName
region:(CLRegion *)region
regionTriggersOnce:(BOOL)regionTriggersOnce
category:(NSString *)category NS_AVAILABLE_IOS(8_0);
/*!
* @abstract 前台展示本地推送
*
* @param notification 本地推送对象
* @param notificationKey 需要前台显示的本地推送通知的标示符
*
* @discussion 默认App在前台运行时不会进行弹窗在程序接收通知调用此接口可实现指定的推送弹窗。
*/
+ (void)showLocalNotificationAtFront:(UILocalNotification *)notification
identifierKey:(NSString *)notificationKey;
/*!
* @abstract 删除本地推送定义
*
* @param notificationKey 本地推送标示符
* @param myUILocalNotification 本地推送对象
*/
+ (void)deleteLocalNotificationWithIdentifierKey:(NSString *)notificationKey;
/*!
* @abstract 删除本地推送定义
*/
+ (void)deleteLocalNotification:(UILocalNotification *)localNotification;
/*!
* @abstract 获取指定通知
*
* @param notificationKey 本地推送标示符
* @return 本地推送对象数组, [array count]为0时表示没找到
*/
+ (NSArray *)findLocalNotificationWithIdentifier:(NSString *)notificationKey;
/*!
* @abstract 清除所有本地推送对象
*/
+ (void)clearAllLocalNotifications;
///----------------------------------------------------
/// @name Server badge 服务器端 badge 功能
///----------------------------------------------------
/*!
* @abstract 设置角标(到服务器)
*
* @param value 新的值. 会覆盖服务器上保存的值(这个用户)
*
* @discussion 本接口不会改变应用本地的角标值.
* 本地仍须调用 UIApplication:setApplicationIconBadgeNumber 函数来设置脚标.
*
* 本接口用于配合 JPush 提供的服务器端角标功能.
* 该功能解决的问题是, 服务器端推送 APNs 时, 并不知道客户端原来已经存在的角标是多少, 指定一个固定的数字不太合理.
*
* JPush 服务器端脚标功能提供:
*
* - 通过本 API 把当前客户端(当前这个用户的) 的实际 badge 设置到服务器端保存起来;
* - 调用服务器端 API 发 APNs 时(通常这个调用是批量针对大量用户),
* 使用 "+1" 的语义, 来表达需要基于目标用户实际的 badge 值(保存的) +1 来下发通知时带上新的 badge 值;
*/
+ (BOOL)setBadge:(NSInteger)value;
/*!
* @abstract 重置脚标(为0)
*
* @discussion 相当于 [setBadge:0] 的效果.
* 参考 [JPUSHService setBadge:] 说明来理解其作用.
*/
+ (void)resetBadge;
///----------------------------------------------------
/// @name Logs and others 日志与其他
///----------------------------------------------------
/*!
* @abstract JPush标识此设备的 registrationID
*
* @discussion SDK注册成功后, 调用此接口获取到 registrationID 才能够获取到.
*
* JPush 支持根据 registrationID 来进行推送.
* 如果你需要此功能, 应该通过此接口获取到 registrationID 后, 上报到你自己的服务器端, 并保存下来.
*
* 更多的理解请参考 JPush 的文档网站.
*/
+ (NSString *)registrationID;
/*!
* @abstract 打开日志级别到 Debug
*
* @discussion JMessage iOS 的日志系统参考 Android 设计了级别.
* 从低到高是: Verbose, Debug, Info, Warning, Error.
* 对日志级别的进一步理解, 请参考 Android 相关的说明.
*
* SDK 默认开启的日志级别为: Info. 只显示必要的信息, 不打印调试日志.
*
* 调用本接口可打开日志级别为: Debug, 打印调试日志.
*/
+ (void)setDebugMode;
/*!
* @abstract 关闭日志
*
* @discussion 关于日志级别的说明, 参考 [JPUSHService setDebugMode]
*
* 虽说是关闭日志, 但还是会打印 Warning, Error 日志. 这二种日志级别, 在程序运行正常时, 不应有打印输出.
*
* 建议在发布的版本里, 调用此接口, 关闭掉日志打印.
*/
+ (void)setLogOFF;
@end

Binary file not shown.

Binary file not shown.

View File

@@ -1,4 +1,5 @@
var JPushPlugin = function(){
};
@@ -43,9 +44,14 @@ JPushPlugin.prototype.beginLogPageView = function(pageName,duration){
}
JPushPlugin.prototype.setApplicationIconBadgeNumber = function(badge){
if(this.isPlatformIOS()){
this.call_native( "setApplicationIconBadgeNumber",[badge],null);
this.call_native( "setApplicationIconBadgeNumber",[badge],null);
}
}
JPushPlugin.prototype.getApplicationIconBadgeNumber = function(callback){
if(this.isPlatformIOS()){
this.call_native( "getApplicationIconBadgeNumber",[],callback);
}
}
JPushPlugin.prototype.setTagsWithAlias = function(tags,alias){
try{
@@ -328,3 +334,5 @@ if(!window.plugins.jPushPlugin){
module.exports = new JPushPlugin();