Compare commits

..

71 Commits

Author SHA1 Message Date
zhangqinghe
e66336f670 update android sdk version to v1.7.3 2015-03-17 14:18:12 +08:00
zhangqinghe
2797bdd0e7 add ducoment about with JPushPlugin.h 2015-03-10 17:38:14 +08:00
zhangqinghe
a197975d03 upadte js event 'jpush.receiveNotification' 2015-03-10 16:58:09 +08:00
zhangqinghe
27c4fe7b26 add event jpush.receiveNotification in object-c file 2015-03-10 16:46:44 +08:00
zhangqinghe
aae9e8314a add js event jpush.receiveNotification 2015-03-10 16:37:08 +08:00
zhangqinghe
7d489c7f20 Merge branch 'dev' of ssh://github.com/jpush/jpush-phonegap-plugin into dev 2015-02-14 16:26:05 +08:00
zhangqinghe
c3cfa01e60 delete openNotificaiton error simple 2015-02-14 16:24:09 +08:00
zhangqinghe
27ebdd6809 增加了打开通知的event回调 2015-02-14 16:24:09 +08:00
qinghe.zhang
e945bcf53d Merge pull request #29 from Samurais/master
#28 stream cn.jpush.android.EXTRA from JSONObject to String
2015-02-14 16:23:01 +08:00
Samurais
cc858c2464 #28 stream cn.jpush.android.EXTRA from JSONObject to String 2015-02-14 16:07:31 +08:00
zhangqinghe
1b93f5e026 delete openNotificaiton error simple 2015-01-27 18:31:05 +08:00
zhangqinghe
46e0c1879c 增加了打开通知的event回调 2015-01-27 18:19:16 +08:00
zhangqinghe
fe7c52f2c9 add open notificaiton event interface's document 2015-01-27 15:40:46 +08:00
zhangqinghe
f217eda463 添加统计代码 2015-01-26 14:40:44 +08:00
zhangqinghe
95fc690dd3 fix ducoment's error 2015-01-26 14:30:28 +08:00
zhangqinghe
260c298f6b 增加统计接口 2015-01-26 14:23:45 +08:00
zhangqinghe
7c1c29a7ec add interface init and setDebugMode in example 2015-01-19 17:48:41 +08:00
qinghe.zhang
0aed054039 Merge pull request #22 from Samurais/master
#21 fix json parse issue in openNotificationInAndroidCallback
2015-01-19 17:07:01 +08:00
zhangqinghe
b018a2748c change plugin vertion to 2.0.0 2015-01-19 16:49:37 +08:00
zhangqinghe
39b7987b25 修正安装文档,使安装过程更简洁 2015-01-19 16:37:44 +08:00
zhangqinghe
2c3bd5ab38 升级android sdk 到1.7.2 2015-01-19 13:32:56 +08:00
zhangqinghe
3e23fb9129 调整参数名称和函数在文件的位置 2015-01-16 15:09:26 +08:00
zhangqinghe
495497f3ac 添加api说明文档 2015-01-16 15:02:06 +08:00
zhangqinghe
ca72c5eba1 修改统计功能的参数 2015-01-16 10:50:31 +08:00
zhangqinghe
4e687db4d3 增加了benginLogPageView 2015-01-16 10:42:06 +08:00
zhangqinghe
3d74b92952 android增加本地通知 2015-01-15 10:31:43 +08:00
zhangqinghe
5a33f0c6e2 Merge branch 'dev' of ssh://github.com/jpush/jpush-phonegap-plugin into dev 2015-01-04 09:42:26 +08:00
zhangqinghe
f80c4ca59c add gitignore file 2015-01-04 09:41:29 +08:00
zhangqinghe
da08b93e43 添加了ios 停止推送的js接口 2015-01-04 09:39:28 +08:00
zhangqinghe
9279611fcd add ios sdk 1.8.1 2015-01-04 09:36:19 +08:00
zhangqinghe
3aec197d1d change document 2015-01-04 09:34:16 +08:00
qinghe.zhang
abd2a5bac9 Update index.html 2014-12-30 18:04:24 +08:00
Samurais
95194695fe #21 fix json parse issue in openNotificationInAndroidCallback 2014-12-15 17:07:55 +08:00
zhangqinghe
360cdd4c95 Merge branch 'dev' of ssh://github.com/jpush/jpush-phonegap-plugin into dev
Conflicts:
	README.md
2014-12-09 14:41:57 +08:00
zhangqinghe
9fbd45c7c7 in JPushPlugin.java add import xxx.entry 2014-12-09 14:35:08 +08:00
zhangqinghe
894c2f902d 在文档中添加 import xxx.R 2014-12-08 11:59:54 +08:00
zhangqinghe
70e2d6d9e2 修改点击通知的参数传递方式(android) 2014-12-08 11:01:49 +08:00
zhangqinghe
ae42986fc9 添加了ios 停止推送的js接口 2014-11-20 10:24:49 +08:00
zhangqinghe
1b2ffe13d8 fix document 2014-11-20 10:24:49 +08:00
reyoung
1b0c64f235 Fix receive typo in JPushPlugin
Fix typo, make jpush can receive message in android...
2014-11-20 10:24:48 +08:00
zhangqinghe
219ae72758 添加了ios 停止推送的js接口 2014-11-18 14:01:18 +08:00
zhangqinghe
9536989082 fix document 2014-09-24 20:33:55 +08:00
zhangqinghe
b1e00baeb8 add ios sdk 1.8.1 2014-09-24 20:05:50 +08:00
zhangqinghe
e24a929ed3 change document 2014-09-24 20:05:49 +08:00
zhangqinghe
2610f4ea9e add android 1.6.4 and change plugin.xml 2014-09-24 20:05:49 +08:00
zhangqinghe
aa53b5a214 add ios sdk 1.8.1 2014-09-24 20:02:07 +08:00
zhangqinghe
acaff1c403 change document 2014-09-24 09:19:32 +08:00
zhangqinghe
288253169a add android 1.6.4 and change plugin.xml 2014-09-22 10:21:01 +08:00
qinghe.zhang
95587f9379 Merge pull request #10 from reyoung/patch-1
Fix receive typo in JPushPlugin
2014-08-11 11:19:58 +08:00
reyoung
0eda4d42df Fix receive typo in JPushPlugin
Fix typo, make jpush can receive message in android...
2014-08-06 17:43:01 +08:00
zhangqinghe
206efc7b2c change sdk vertion 1.7.3 2014-07-31 13:39:04 +08:00
zhangqinghe
5c671fadc9 fix openNotification crash in plugin for android 2014-07-28 20:11:27 +08:00
zhangqinghe
904384d8ae document about build 2014-07-25 10:14:32 +08:00
zhangqinghe
4215437bd6 document add abaut phoengap cloud build 2014-07-25 10:06:06 +08:00
zhangqinghe
8db89c9f2e fix document in appkey 2014-07-24 19:09:29 +08:00
zhangqinghe
992246235d delete callback not used 2014-07-24 16:41:42 +08:00
zhangqinghe
8e0fee7276 fix last commit error 2014-07-24 14:52:14 +08:00
zhangqinghe
734077536b add new JPushPlugin ,else plugin not loaded 2014-07-23 17:08:13 +08:00
zhangqinghe
bce9508ec5 find back receive message form android 2014-07-23 14:46:02 +08:00
zhangqinghe
ea685713db delete openNotificationForIos 2014-07-23 14:39:47 +08:00
zhangqinghe
4c810fcaa9 change verion to v1.5.4 2014-07-23 09:52:18 +08:00
zhangqinghe
213e5b7bb1 spelling mistakes 2014-07-22 20:14:01 +08:00
zhangqinghe
1af99fe4bf add message in app 2014-07-22 18:51:48 +08:00
zhangqinghe
3e55f6f2c4 fix android open notification and message callback in js 2014-07-17 09:51:45 +08:00
zhangqinghe
ec40fd3e58 delete more log 2014-07-16 15:24:59 +08:00
zhangqinghe
e6819f54e2 fix log 2014-07-10 18:09:06 +08:00
zhangqinghe
386d1282e9 delete space in document 2014-07-10 15:51:06 +08:00
zhangqinghe
d55a46c54c fix document 2014-07-10 15:46:30 +08:00
zhangqinghe
bfe0a76ae0 fix a part Android Doc form READ.me 2014-07-10 15:03:30 +08:00
zhangqinghe
7cc3239e1b fix push notificaiton and add open notificaiotn evet 2014-07-10 14:57:03 +08:00
qinghe.zhang
34857a1eea Update README.md 2014-06-27 10:05:27 +08:00
17 changed files with 1406 additions and 347 deletions

1
.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
.DS_Store

1008
README.md

File diff suppressed because it is too large Load Diff

View File

@@ -11,7 +11,7 @@
<script type="text/javascript" src="cordova.js"></script>
<script type="text/javascript">
var onDeviceReady = function(){
console.log("Device ready!")
console.log("JPushPlugin:Device ready!")
initiateUI();
}
var onTagsWithAlias = function(event){
@@ -26,9 +26,30 @@
console.log(exception)
}
}
var onOpenNotification = function(event){
try{
var alert = event.alert;
var extras = event.extras;
console.log(alert);
//console.log(extras);
}
catch(exeption){
console.log(exception)
}
}
var onReceiveNotification = function(event){
try{
var alert = event.aps.alert;
console.log("JPushPlugin:onReceiveNotification key aps.alert:"+alert);
}
catch(exeption){
console.log(exception)
}
}
var onGetRegistradionID = function(data) {
try{
console.log("index.registrationID:"+data)
console.log("JPushPlugin:registrationID is "+data)
$("#registrationid").html(data);
}
@@ -38,9 +59,20 @@
}
var initiateUI = function(){
window.plugins.jPushPlugin.getRegistrationID(onGetRegistradionID);
try{
window.plugins.jPushPlugin.init();
window.plugins.jPushPlugin.setDebugMode(true);
window.plugins.jPushPlugin.getRegistrationID(onGetRegistradionID);
// var extras={"name":"json"};
// window.plugins.jPushPlugin.addLocalNotification(1,"hh","ln",1111,1000*60,extras);
// window.plugins.jPushPlugin.removeLocalNotification(1111);
// window.plugins.jPushPlugin.clearLocalNotifications();
}
catch(exception){
console.log(exception);
}
//test android interface
//window.plugins.jPushPlugin.getNotification(onNotification);
//window.plugins.jPushPlugin.stopPush()
//window.plugins.jPushPlugin.resumePush();
//window.plugins.jPushPlugin.clearAllNoticication();
@@ -48,7 +80,7 @@
//window.plugins.jPushPlugin.stopPush();
//window.plugins.jPushPlugin.isPushStopped(onIsPushStopped);
//window.plugins.jPushPlugin.init();
//window.plugins.jPushPlugin.setDebugable(true);
//window.plugins.jPushPlugin.setDebugMode(true);
//window.plugins.jPushPlugin.startLogPageView("mianPage");
$("#setTagWithAliasButton").click(function(ev) {
@@ -80,18 +112,16 @@
}
})
}
document.addEventListener("jpush.receiveNotification", onReceiveNotification, false);
document.addEventListener("jpush.setTagsWithAlias", onTagsWithAlias, false);
document.addEventListener("deviceready", onDeviceReady, false);
document.addEventListener("deviceready", onDeviceReady, false);
document.addEventListener("jpush.openNotification", onOpenNotification, false);
</script>
</head>
<body>
<div data-role="page" id="page">
<div data-role="header" class="ui-bar ui-bar-b">
<center>
<img border="0" src="img/logo.png" alt="Urban Airship" align="center" />
</center>
</div>
<div data-role="content">
<form>
<div class="ui-body ui-body-b">

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="1.5.3">
version="2.0.0">
<name>JPush Plugin</name>
<description>JPush for cordova plugin</description>
@@ -29,7 +29,7 @@
<source-file src="src/ios/Plugins/JPushPlugin.m"/>
<header-file src="src/ios/lib/APService.h" />
<source-file src="src/ios/lib/libPushSDK.a" framework="true" />
<source-file src="src/ios/lib/libPushSDK-1.8.2.a" framework="true" />
<resource-file src="src/ios/PushConfig.plist" />
@@ -153,10 +153,11 @@
<receiver android:name="cn.jpush.android.service.AlarmReceiver"/>
<!-- Required . Enable it you can get statistics data with channel -->
<meta-data android:name="JPUSH_CHANNEL" android:value="developer-default"/>
<meta-data android:name="JPUSH_APPKEY" android:value="299d0fee887820e7d90a68b2"/>
<meta-data android:name="JPUSH_APPKEY" android:value="your appkey"/>
</config-file>
<source-file src="src/android/jpush-sdk-release1.6.1.jar" target-dir="libs"/>
<source-file src="src/android/libjpush.so" target-dir="libs/armeabi"/>
<source-file src="src/android/jpush-sdk-release1.7.3.jar" target-dir="libs"/>
<source-file src="src/android/armeabi/libjpush173.so" target-dir="libs/armeabi"/>
<source-file src="src/android/armeabi-v7a/libjpush173.so" target-dir="libs/armeabi-v7a"/>
<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"/>
<source-file src="src/android/test_notification_layout.xml" target-dir="res/layout"/>

View File

@@ -17,12 +17,14 @@ import org.apache.cordova.CordovaWebView;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.Map.Entry;
import com.thi.pushtest.R;
import your.package.name.R;
import cn.jpush.android.api.BasicPushNotificationBuilder;
import cn.jpush.android.api.CustomPushNotificationBuilder;
import cn.jpush.android.api.JPushInterface;
import cn.jpush.android.data.JPushLocalNotification;
import cn.jpush.android.api.TagAliasCallback;
public class JPushPlugin extends CordovaPlugin {
@@ -37,19 +39,25 @@ public class JPushPlugin extends CordovaPlugin {
"setCustomPushNotificationBuilder",
"setPushTime",
"init",
"setDebugable",
"setDebugMode",
"stopPush",
"resumePush",
"isPushStopped",
"setLatestNotificationNum",
"setPushTime",
"clearAllNotification");
"clearAllNotification",
"addLocalNotification",
"removeLocalNotification",
"clearLocalNotifications",
"onResume",
"onPause",
"reportNotificationOpened");
private ExecutorService threadPool = Executors.newFixedThreadPool(1);
private static JPushPlugin instance;
public static String notificationAlert;
public static Map<String, String> notificationExtras=new HashMap<String, String>();
public static Map<String, Object> notificationExtras=new HashMap<String, Object>();
public JPushPlugin() {
instance = this;
@@ -58,29 +66,65 @@ public class JPushPlugin extends CordovaPlugin {
@Override
public void initialize(CordovaInterface cordova, CordovaWebView webView) {
super.initialize(cordova, webView);
JPushInterface.setDebugMode(true);
JPushInterface.init(cordova.getActivity().getApplicationContext());
//JPushInterface.setDebugMode(true);
//JPushInterface.init(cordova.getActivity().getApplicationContext());
}
private static JSONObject notificationObject(String message,
Map<String, String> extras) {
Map<String, Object> extras) {
JSONObject data = new JSONObject();
try {
data.put("message", message);
data.put("extras", new JSONObject(extras));
JSONObject jExtras = new JSONObject();
for(Entry<String,Object> entry:extras.entrySet()){
if(entry.getKey().equals("cn.jpush.android.EXTRA")){
JSONObject jo = new JSONObject((String)entry.getValue());
jExtras.put("cn.jpush.android.EXTRA", jo);
} else {
jExtras.put(entry.getKey(),entry.getValue());
}
}
if(jExtras.length()>0)
{
data.put("extras", jExtras);
}
} catch (JSONException e) {
}
return data;
}
static void transmitPush(String message, Map<String, String> extras) {
private static JSONObject openNotificationObject(String alert,
Map<String, Object> extras){
JSONObject data = new JSONObject();
try{
data.put("alert", alert);
JSONObject jExtras = new JSONObject();
for(Entry<String,Object> entry:extras.entrySet()){
if(entry.getKey().equals("cn.jpush.android.EXTRA")){
JSONObject jo = new JSONObject((String)entry.getValue());
jExtras.put("cn.jpush.android.EXTRA", jo);
}else{
jExtras.put(entry.getKey(),entry.getValue());
}
}
if(jExtras.length()>0)
{
data.put("extras", jExtras);
}
} catch (JSONException e) {
}
return data;
}
static void transmitPush(String message, Map<String, Object> extras) {
if (instance == null) {
return;
}
JSONObject data = notificationObject(message, extras);
String js = String
.format("window.plugins.jPushPlugin.pushCallback(%s);",
.format("window.plugins.jPushPlugin.receiveMessageInAndroidCallback('%s');",
data.toString());
try {
instance.webView.sendJavascript(js);
@@ -90,7 +134,27 @@ public class JPushPlugin extends CordovaPlugin {
}
}
static void transmitOpen(String alert, Map<String, Object> extras) {
if (instance == null) {
return;
}
JSONObject data = openNotificationObject(alert, extras);
String js = String
.format("window.plugins.jPushPlugin.openNotificationInAndroidCallback('%s');",
data.toString());
try {
instance.webView.sendJavascript(js);
String jsEvent=String
.format("cordova.fireDocumentEvent('jpush.openNotification',%s)",
data.toString());
instance.webView.sendJavascript(jsEvent);
} catch (NullPointerException e) {
} catch (Exception e) {
}
}
@Override
public boolean execute(final String action, final JSONArray data,
final CallbackContext callbackContext) throws JSONException {
@@ -114,20 +178,21 @@ public class JPushPlugin extends CordovaPlugin {
void init(JSONArray data,CallbackContext callbackContext){
JPushInterface.init(this.cordova.getActivity().getApplicationContext());
callbackContext.success();
//callbackContext.success();
}
void setDebugable(JSONArray data, CallbackContext callbackContext) {
String mode;
void setDebugMode(JSONArray data, CallbackContext callbackContext) {
boolean mode;
try {
mode = data.getString(0);
if (mode.equals("true")) {
JPushInterface.setDebugMode(true);
} else if (mode.equals("false")) {
JPushInterface.setDebugMode(false);
} else {
callbackContext.error("error mode");
}
mode = data.getBoolean(0);
// if (mode.equals("true")) {
// JPushInterface.setDebugMode(true);
// } else if (mode.equals("false")) {
// JPushInterface.setDebugMode(false);
// } else {
// callbackContext.error("error mode");
// }
JPushInterface.setDebugMode(mode);
callbackContext.success();
} catch (JSONException e) {
}
@@ -147,8 +212,8 @@ public class JPushPlugin extends CordovaPlugin {
void isPushStopped(JSONArray data,
CallbackContext callbackContext){
boolean isStoped =JPushInterface.isPushStopped(this.cordova.getActivity().getApplicationContext());
if(isStoped){
boolean isStopped =JPushInterface.isPushStopped(this.cordova.getActivity().getApplicationContext());
if(isStopped){
callbackContext.success(1);
}else{
callbackContext.success(0);
@@ -165,7 +230,7 @@ public class JPushPlugin extends CordovaPlugin {
callbackContext.error("error reading num json");
}
if(num != -1){
JPushInterface.setLatestNotifactionNumber(this.cordova.getActivity().getApplicationContext(), num);
JPushInterface.setLatestNotificationNumber(this.cordova.getActivity().getApplicationContext(), num);
}else{
callbackContext.error("error num");
}
@@ -174,13 +239,13 @@ public class JPushPlugin extends CordovaPlugin {
void setPushTime(JSONArray data,
CallbackContext callbackContext){
Set<Integer> days = new HashSet<Integer>();
JSONArray dayArr;
JSONArray dayArray;
int startHour = -1;
int endHour = -1;
try {
dayArr = data.getJSONArray(0);
for (int i = 0; i < dayArr.length(); i++) {
days.add(dayArr.getInt(i));
dayArray = data.getJSONArray(0);
for (int i = 0; i < dayArray.length(); i++) {
days.add(dayArray.getInt(i));
}
} catch (JSONException e) {
e.printStackTrace();
@@ -200,6 +265,23 @@ public class JPushPlugin extends CordovaPlugin {
String regID= JPushInterface.getRegistrationID(this.cordova.getActivity().getApplicationContext());
callbackContext.success(regID);
}
void onResume(JSONArray data, CallbackContext callbackContext) {
JPushInterface.onResume(this.cordova.getActivity());
}
void onPause(JSONArray data, CallbackContext callbackContext) {
JPushInterface.onPause(this.cordova.getActivity());
}
void reportNotificationOpened(JSONArray data, CallbackContext callbackContext) {
try {
String msgID;
msgID = data.getString(0);
JPushInterface.reportNotificationOpened(this.cordova.getActivity(),msgID);
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
void setTags(JSONArray data, CallbackContext callbackContext) {
@@ -212,8 +294,11 @@ public class JPushPlugin extends CordovaPlugin {
tags= new HashSet<String>();
}else{
tagStr = data.getString(0);
String[] tagArr = tagStr.split(",");
for (String tag : tagArr) {
String[] tagArray = tagStr.split(",");
for (String tag : tagArray) {
if(tags==null){
tags= new HashSet<String>();
}
tags.add(tag);
}
}
@@ -244,9 +329,9 @@ public class JPushPlugin extends CordovaPlugin {
String alias;
try {
alias = data.getString(0);
JSONArray tagsArr = data.getJSONArray(1);
for (int i = 0; i < tagsArr.length(); i++) {
tags.add(tagsArr.getString(i));
JSONArray tagsArray = data.getJSONArray(1);
for (int i = 0; i < tagsArray.length(); i++) {
tags.add(tagsArray.getString(i));
}
JPushInterface.setAliasAndTags(this.cordova.getActivity()
@@ -258,23 +343,23 @@ public class JPushPlugin extends CordovaPlugin {
}
}
void getNotification(JSONArray data, CallbackContext callBackContext) {
String alert = JPushPlugin.notificationAlert;
Map<String, String> extras = JPushPlugin.notificationExtras;
JSONObject jsonData = new JSONObject();
try {
jsonData.put("message", alert);
jsonData.put("extras", new JSONObject(extras));
} catch (JSONException e) {
e.printStackTrace();
}
callBackContext.success(jsonData);
JPushPlugin.notificationAlert = "";
JPushPlugin.notificationExtras = new HashMap<String, String>();
}
// void getNotification(JSONArray data, CallbackContext callBackContext) {
// String alert = JPushPlugin.notificationAlert;
// Map<String, String> extras = JPushPlugin.notificationExtras;
//
// JSONObject jsonData = new JSONObject();
// try {
// jsonData.put("message", alert);
// jsonData.put("extras", new JSONObject(extras));
// } catch (JSONException e) {
// e.printStackTrace();
// }
//
// callBackContext.success(jsonData);
//
// JPushPlugin.notificationAlert = "";
// JPushPlugin.notificationExtras = new HashMap<String, Obl>();
// }
void setBasicPushNotificationBuilder(JSONArray data,
CallbackContext callbackContext) {
@@ -288,7 +373,7 @@ public class JPushPlugin extends CordovaPlugin {
} catch (JSONException e) {
e.printStackTrace();
}
callbackContext.success(obj);
//callbackContext.success(obj);
}
void setCustomPushNotificationBuilder(JSONArray data,
@@ -305,13 +390,13 @@ public class JPushPlugin extends CordovaPlugin {
} catch (JSONException e) {
e.printStackTrace();
}
callbackContext.success(obj);
//callbackContext.success(obj);
}
void clearAllNotification(JSONArray data,
CallbackContext callbackContext){
JPushInterface.clearAllNotifications(this.cordova.getActivity());
callbackContext.success();
//callbackContext.success();
}
void clearNotificationById(JSONArray data,
@@ -329,6 +414,41 @@ public class JPushPlugin extends CordovaPlugin {
callbackContext.error("error id");
}
}
void addLocalNotification(JSONArray data,
CallbackContext callbackContext) throws JSONException{
//builderId,content,title,notificaitonID,broadcastTime,extras
int builderId=data.getInt(0);
String content =data.getString(1);
String title = data.getString(2);
int notificationID= data.getInt(3);
int broadcastTime=data.getInt(4);
JSONObject extras=data.getJSONObject(5);
JPushLocalNotification ln = new JPushLocalNotification();
ln.setBuilderId(builderId);
ln.setContent(content);
ln.setTitle(title);
ln.setNotificationId(notificationID) ;
ln.setBroadcastTime(System.currentTimeMillis() + broadcastTime);
ln.setExtras(extras.toString()) ;
JPushInterface.addLocalNotification(this.cordova.getActivity(), ln);
}
void removeLocalNotification(JSONArray data,
CallbackContext callbackContext) throws JSONException{
int notificationID=data.getInt(0);
JPushInterface.removeLocalNotification(this.cordova.getActivity(),notificationID);
}
void clearLocalNotifications(JSONArray data,
CallbackContext callbackContext){
JPushInterface.clearLocalNotifications(this.cordova.getActivity());
}
private final TagAliasCallback mTagWithAliasCallback = new TagAliasCallback() {
@@ -348,10 +468,6 @@ public class JPushPlugin extends CordovaPlugin {
.format("cordova.fireDocumentEvent('jpush.setTagsWithAlias',%s)",
data.toString());
instance.webView.sendJavascript(jsEvent);
String js = String
.format("window.plugins.jPushPlugin.pushCallback('%s');",
data.toString());
instance.webView.sendJavascript(js);
} catch (JSONException e) {

View File

@@ -35,13 +35,13 @@ public class MyReceiver extends BroadcastReceiver {
}
private void handlingReceivedMessage(Intent intent) {
String msg = intent.getStringExtra(JPushInterface.EXTRA_MESSAGE);
Map<String,String> extras = getNotificationExtras(intent);
Map<String,Object> extras = getNotificationExtras(intent);
JPushPlugin.transmitPush(msg, extras);
}
private void handlingNotificationOpen(Context context,Intent intent){
String alert = intent.getStringExtra(JPushInterface.EXTRA_ALERT);
Map<String,String> extras = getNotificationExtras(intent);
Map<String,Object> extras = getNotificationExtras(intent);
Intent launch = context.getPackageManager().getLaunchIntentForPackage(context.getPackageName());
launch.addCategory(Intent.CATEGORY_LAUNCHER);
@@ -50,19 +50,25 @@ public class MyReceiver extends BroadcastReceiver {
JPushPlugin.notificationAlert = alert;
JPushPlugin.notificationExtras = extras;
JPushPlugin.transmitOpen(alert, extras);
context.startActivity(launch);
}
private Map<String, String> getNotificationExtras(Intent intent) {
Map<String, String> extrasMap = new HashMap<String, String>();
private Map<String, Object> getNotificationExtras(Intent intent) {
Map<String, Object> extrasMap = new HashMap<String, Object>();
for (String key : intent.getExtras().keySet()) {
if (!IGNORED_EXTRAS_KEYS.contains(key)) {
Log.e("key","key:"+key);
extrasMap.put(key, intent.getStringExtra(key));
Log.e("key","key:"+key);
if (key.equals(JPushInterface.EXTRA_NOTIFICATION_ID)){
extrasMap.put(key, intent.getIntExtra(key,0));
}else{
extrasMap.put(key, intent.getStringExtra(key));
}
}
}
return extrasMap;
}
private static final List<String> IGNORED_EXTRAS_KEYS =
Arrays.asList("cn.jpush.android.TITLE","cn.jpush.android.MESSAGE","cn.jpush.android.APPKEY");
Arrays.asList("cn.jpush.android.TITLE","cn.jpush.android.MESSAGE","cn.jpush.android.APPKEY","cn.jpush.android.NOTIFICATION_CONTENT_TITLE");
}

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -8,6 +8,8 @@
#import <Cordova/CDV.h>
#define kJPushPluginReceiveNotification @"JPushPluginReceiveNofication"
@interface JPushPlugin : CDVPlugin{
}

View File

@@ -11,11 +11,30 @@
@implementation JPushPlugin
- (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];
}
return self;
}
-(void)setTagsWithAlias:(CDVInvokedUrlCommand*)command{
NSArray *arguments=command.arguments;
if (!arguments||[arguments count]<2) {
[self writeJavascript:[NSString stringWithFormat:@"window.plugins.jPushPlugin.pushCallback('%@')",@""]];
// [self writeJavascript:[NSString stringWithFormat:@"window.plugins.jPushPlugin.pushCallback('%@')",@""]];
return ;
}
NSString *alias=[arguments objectAtIndex:0];
@@ -51,8 +70,8 @@
-(void)getRegistrationID:(CDVInvokedUrlCommand*)command{
NSString* registratonID = [APService registrionID];
CDVPluginResult *result=[self pluginResultForValue:registratonID];
NSString* registrationID = [APService registrationID];
CDVPluginResult *result=[self pluginResultForValue:registrationID];
if (result) {
[self succeedWithPluginResult:result withCallbackID:command.callbackId];
} else {
@@ -78,7 +97,7 @@
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]];
// [self writeJavascript:[NSString stringWithFormat:@"window.plugins.jPushPlugin.pushCallback('%@')",jsonString]];
});
}
@@ -106,7 +125,44 @@
}
}
-(void)beginLogPageView:(CDVInvokedUrlCommand*)command{
NSArray *arguments=command.arguments;
if (!arguments||[arguments count]<2) {
NSLog(@"beginLogPageView argument error");
return ;
}
NSString * pageName=[arguments objectAtIndex:0];
int duration=[[arguments objectAtIndex:0]intValue];
if (pageName) {
[APService beginLogPageView:pageName duration:duration];
}
}
-(void)setBadge:(CDVInvokedUrlCommand*)command{
NSArray *argument=command.arguments;
if ([argument count]<1) {
NSLog(@"setBadge argument error!");
return;
}
NSNumber *badge=[argument objectAtIndex:0];
[APService 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)failWithCallbackID:(NSString *)callbackID {
CDVPluginResult *result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR];
[self.commandDelegate sendPluginResult:result callbackId:callbackID];
@@ -141,5 +197,38 @@
return result;
}
- (void)networkDidReceiveMessage:(NSNotification *)notification {
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(), ^{
[self writeJavascript:[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];
dispatch_async(dispatch_get_main_queue(), ^{
[self.commandDelegate evalJs:[NSString stringWithFormat:@"cordova.fireDocumentEvent('jpush.receiveNotification',%@)",jsonString]];
});
}
@end

View File

@@ -4,23 +4,27 @@
//
// Created by JPush on 12-8-15.
// Copyright (c) 2012年 HXHG. All rights reserved.
// Version: 1.7.1
// Version: 1.8.2
#import <Foundation/Foundation.h>
@class CLRegion;
@class UILocalNotification;
extern NSString *const kAPNetworkDidSetupNotification; // 建立连接
extern NSString *const kAPNetworkDidCloseNotification; // 关闭连接
extern NSString *const kAPNetworkDidRegisterNotification; // 注册成功
extern NSString *const kAPNetworkDidLoginNotification; // 登录成功
extern NSString *const kJPFNetworkDidSetupNotification; // 建立连接
extern NSString *const kJPFNetworkDidCloseNotification; // 关闭连接
extern NSString *const kJPFNetworkDidRegisterNotification; // 注册成功
extern NSString *const kJPFNetworkDidLoginNotification; // 登录成功
extern NSString *const
kAPNetworkDidReceiveMessageNotification; // 收到消息(非APNS)
extern NSString *const kAPServiceErrorNotification; // 错误提示
kJPFNetworkDidReceiveMessageNotification; // 收到消息(非APNS)
extern NSString *const kJPFServiceErrorNotification; // 错误提示
@class CLLocation;
@interface APService : NSObject
#pragma - mark 基本功能
// 以下四个接口是必须调用的
+ (void)setupWithOption:(NSDictionary *)launchingOption; // 初始化
+ (void)registerForRemoteNotificationTypes:(int)types; // 注册APNS类型
+ (void)registerForRemoteNotificationTypes:(NSUInteger)types
categories:(NSSet *)categories; // 注册APNS类型
+ (void)registerDeviceToken:(NSData *)deviceToken; // 向服务器上报Device Token
+ (void)handleRemoteNotification:(NSDictionary *)
remoteInfo; // 处理收到的APNS消息向服务器上报收到APNS消息
@@ -44,6 +48,7 @@ extern NSString *const kAPServiceErrorNotification; // 错误提示
// 用于过滤出正确可用的tags如果总数量超出最大限制则返回最大数量的靠前的可用tags
+ (NSSet *)filterValidTags:(NSSet *)tags;
#pragma - mark 上报日志
/**
* 记录页面停留时间功能。
* startLogPageView和stopLogPageView为自动计算停留时间
@@ -56,13 +61,121 @@ extern NSString *const kAPServiceErrorNotification; // 错误提示
+ (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;
#pragma - mark 获取用户标示符
/**
* get the UDID
*/
+ (NSString *)openUDID DEPRECATED_ATTRIBUTE; // UDID
/**
* get RegistionID
* get RegistrationID
*/
+ (NSString *)registrionID;
+ (NSString *)registrationID;
#pragma - mark 打印日志信息配置
/**
* setDebugMode获取更多的Log信息
* 开发过程中建议开启DebugMode
*
* setLogOFF关闭除了错误信息外的所有Log
* 发布时建议开启LogOFF用于节省性能开销
*
* 默认为不开启DebugLog,只显示基本的信息
*/
+ (void)setDebugMode;
+ (void)setLogOFF;
@end

Binary file not shown.

Binary file not shown.

View File

@@ -1,5 +1,7 @@
var JPushPlugin = function(){
};
//private plugin function
JPushPlugin.prototype.isPlatformIOS = function(){
return device.platform == "iPhone" || device.platform == "iPad" || device.platform == "iPod touch" || device.platform == "iOS"
@@ -14,16 +16,23 @@ JPushPlugin.prototype.call_native = function(name, args, callback){
ret = cordova.exec(callback,this.error_callback,'JPushPlugin',name,args);
return ret;
}
//public plugin function
JPushPlugin.prototype.startLogPageView = function(data){
JPushPlugin.prototype.startLogPageView = function(pageName){
if(this.isPlatformIOS()){
this.call_native( "startLogPageView",[data],null);
this.call_native( "startLogPageView",[pageName],null);
}
}
JPushPlugin.prototype.stopLogPageView = function(data){
JPushPlugin.prototype.stopLogPageView = function(pageName){
if(this.isPlatformIOS()){
this.call_native( "stopLogPageView",[data],null);
this.call_native( "stopLogPageView",[pageName],null);
}
}
JPushPlugin.prototype.beginLogPageView = function(pageName,duration){
if(this.isPlatformIOS()){
this.call_native( "beginLogPageView",[pageName,duration],null);
}
}
@@ -46,7 +55,24 @@ JPushPlugin.prototype.setTagsWithAlias = function(tags,alias){
}
}
JPushPlugin.prototype.setTags = function(tags){
try{
this.call_native("setTags",tags,null);
}
catch(exception){
console.log(exception);
}
}
JPushPlugin.prototype.setAlias = function(alias){
try{
this.call_native("setAlias",[alias],null);
}
catch(exception){
console.log(exception);
}
}
JPushPlugin.prototype.getRegistrationID = function(callback){
try{
@@ -57,33 +83,90 @@ JPushPlugin.prototype.getRegistrationID = function(callback){
console.log(exception);
}
}
JPushPlugin.prototype.setTags = function(data){
try{
this.call_native("setTags",data,null);
JPushPlugin.prototype.setBadge = function(value){
if(this.isPlatformIOS()){
try{
this.call_native("setBadge",[value],null);
}
catch(exception){
console.log(exception);
}
}
}
JPushPlugin.prototype.resetBadge = function(){
if(this.isPlatformIOS()){
try{
var data=[];
this.call_native("resetBadge",[data],null);
}
catch(exception){
console.log(exception);
}
}
}
JPushPlugin.prototype.setDebugModeFromIos = function(){
if(this.isPlatformIOS()){
var data=[];
this.call_native("setDebugModeFromIos",[data],null);
}
catch(exception){
console.log(exception);
}
JPushPlugin.prototype.setLogOFF = function(){
if(this.isPlatformIOS()){
var data=[];
this.call_native("setLogOFF",[data],null);
}
}
JPushPlugin.prototype.receiveMessageIniOSCallback = function(data){
try{
console.log("JPushPlugin:receiveMessageIniOSCallback--data:"+data);
var bToObj = JSON.parse(data);
var content = bToObj.content;
console.log(content);
}
catch(exception){
console.log("JPushPlugin:receiveMessageIniOSCallback"+exception);
}
}
JPushPlugin.prototype.receiveMessageInAndroidCallback = function(data){
try{
console.log("JPushPlugin:receiveMessageInAndroidCallback");
//console.log(data);
//ecvar bToObj=JSON.parse(data);
//var message = bToObj.message;
//var extras = bToObj.extras;
//console.log(message);
//console.log(extras['cn.jpush.android.MSG_ID']);
//console.log(extras['cn.jpush.android.CONTENT_TYPE']);
//console.log(extras['cn.jpush.android.EXTRA']);
}
catch(exception){
console.log("JPushPlugin:pushCallback "+exception);
}
}
JPushPlugin.prototype.setAlias = function(data){
try{
this.call_native("setAlias",[data],null);
}
catch(exception){
console.log(exception);
}
}
JPushPlugin.prototype.pushCallback = function(data){
//
JPushPlugin.prototype.openNotificationInAndroidCallback = function(data){
try{
console.log("JPushPlugin:openNotificationInAndroidCallback");
console.log(data);
var bToObj=JSON.parse(data);
var code = bToObj.resultCode;
var tags = bToObj.resultTags;
var alias = bToObj.resultAlias;
console.log("JPushPlugin:callBack--code is "+code+" tags is "+tags + " alias is "+alias);
//var bToObj = JSON.parse(data);
//var alert = bToObj.alert;
//var extras = bToObj.extras;
//console.log(alert);
//console.log(extras['cn.jpush.android.MSG_ID']);
//console.log(extras['app']);
//console.log(extras['cn.jpush.android.NOTIFICATION_CONTENT_TITLE']);
//console.log(extras['cn.jpush.android.EXTRA']);
//console.log(extras['cn.jpush.android.PUSH_ID']);
//console.log(extras['cn.jpush.android.NOTIFICATION_ID']);
//console.log("JPushPlugin:openNotificationCallback is ready");
}
catch(exception){
console.log(exception);
@@ -91,13 +174,6 @@ JPushPlugin.prototype.pushCallback = function(data){
}
//android single
JPushPlugin.prototype.getNotification = function (callback) {
if(device.platform == "Android") {
data=[];
this.call_native("getNotification",data,callback);
}
}
JPushPlugin.prototype.setBasicPushNotificationBuilder = function(){
if(device.platform == "Android") {
data=[]
@@ -113,10 +189,8 @@ JPushPlugin.prototype.setCustomPushNotificationBuilder = function(){
}
JPushPlugin.prototype.stopPush = function(){
if(device.platform == "Android") {
data=[];
this.call_native("stopPush",data,null);
}
data=[];
this.call_native("stopPush",data,null);
}
JPushPlugin.prototype.resumePush = function(){
@@ -125,8 +199,13 @@ JPushPlugin.prototype.resumePush = function(){
this.call_native("resumePush",data,null);
}
}
JPushPlugin.prototype.clearAllNoticication = function(){
JPushPlugin.prototype.setDebugMode = function(mode){
if(device.platform == "Android") {
this.call_native("setDebugMode",[mode],null);
}
}
//setDebugMode
JPushPlugin.prototype.clearAllNotification = function(){
if(device.platform == "Android") {
data=[]
this.call_native("clearAllNotification",data,null);
@@ -153,13 +232,49 @@ JPushPlugin.prototype.init = function(){
}
}
JPushPlugin.prototype.setDebugable = function(mode){
JPushPlugin.prototype.setDebugMode = function(mode){
if(device.platform == "Android") {
this.call_native("setDebugable",[mode],null);
this.call_native("setDebugMode",[mode],null);
}
}
JPushPlugin.prototype.addLocalNotification = function(builderId,content,title,notificaitonID,broadcastTime,extras){
if(device.platform == "Android") {
data=[builderId,content,title,notificaitonID,broadcastTime,extras];
this.call_native("addLocalNotification",data,null);
}
}
JPushPlugin.prototype.removeLocalNotification = function(notificationID){
if(device.platform == "Android") {
this.call_native("removeLocalNotification",[notificationID],null);
}
}
JPushPlugin.prototype.clearLocalNotifications = function(){
if(device.platform == "Android") {
data=[]
this.call_native("clearLocalNotifications",data,null);
}
}
JPushPlugin.prototype.onResume = function(){
if(device.platform == "Android") {
data=[]
this.call_native("onResume",data,null);
}
}
JPushPlugin.prototype.onPause = function(){
if(device.platform == "Android") {
data=[]
this.call_native("onPause",data,null);
}
}
//ios single
JPushPlugin.prototype.reportNotificationOpened = function(msgID){
if(device.platform == "Android") {
this.call_native("reportNotificationOpened",[msgID],null);
}
}
//iOS single
if(!window.plugins){