Compare commits

...

19 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
Samurais 95194695fe #21 fix json parse issue in openNotificationInAndroidCallback 2014-12-15 17:07:55 +08:00
13 changed files with 223 additions and 34 deletions
+108 -23
View File
@@ -46,7 +46,13 @@
在APP_KEY和CHANNLE字段 分别添加您的appkey和channle 在APP_KEY和CHANNLE字段 分别添加您的appkey和channle
3. 添加监听系统事件,相应地调用 JPush SDK 提供的 API 来实现功能 3. 在AppDelegate.m中包含头文件
#import "APService.h"
#import "JPushPlugin.h"
4. 在AppDelegate.m文件中,调用 JPush SDK 提供的 API 来实现功能
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{
@@ -86,6 +92,9 @@
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo { - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
// Required // Required
[APService handleRemoteNotification:userInfo]; [APService handleRemoteNotification:userInfo];
[[NSNotificationCenter defaultCenter] postNotificationName:kJPushPluginReceiveNotification
object:userInfo];
} }
###Android 手工安装### ###Android 手工安装###
@@ -487,18 +496,56 @@ iOS
用于iOS收到应用内消息的回调函数(请注意和通知的区别),该函数不需要主动调用 用于iOS收到应用内消息的回调函数(请注意和通知的区别),该函数不需要主动调用
##### 使用平台 ##### 接口定义
JPushPlugin.prototype.receiveMessageIniOSCallback = function(data)
#####平台
iOS iOS
##### 参数说明 #####参数说明
- data 是一个js字符串使用如下代码解析,js具体key根据应用内消息来确定 - data 是一个js字符串使用如下代码解析,js具体key根据应用内消息来确定
var bToObj = JSON.parse(data); var bToObj = JSON.parse(data);
#####返回值
#### event - jpush.receiveNotification
当iOS收到的通知时会触发这个事件
##### 事件定义
cordova.fireDocumentEvent('jpush.receiveNotification',json)
#####平台
iOS
#####使用说明
- 在你需要接收通知的的js文件中加入:
document.addEventListener("jpush.openNotification", onOpenNotification, false);
- onOpenNotification需要这样写:
var onOpenNotification = function(event){
try{
var alert = event.alert;
var extras = event.extras;
console.log(alert);
//console.log(extras);
}
catch(exeption){
console.log(exception)
}
}
#####返回值
#### API - init #### API - init
@@ -719,26 +766,7 @@ android
#### API - receiveMessageInAndroidCallback #### API - receiveMessageInAndroidCallback
用于iOS收到应用内消息的回调函数(请注意和通知的区别),该函数不需要主动调用 用于android收到应用内消息的回调函数(请注意和通知的区别),该函数不需要主动调用
##### 接口定义
JPushPlugin.prototype.receiveMessageInAndroidCallback = function(data)
#####平台
android
##### 参数说明
- data 接收到的js字符串
##### 返回值
#### API - receiveMessageInAndroidCallback
用于iOS收到应用内消息的回调函数(请注意和通知的区别),该函数不需要主动调用
##### 接口定义 ##### 接口定义
@@ -753,4 +781,61 @@ android
##### 返回值 ##### 返回值
#### API - onResume,onPause
本 API 用于“用户使用时长”,“活跃用户”,“用户打开次数”的统计,并上报到服务器,在 Portal 上展示给开发者。
##### 接口定义
JPushPlugin.prototype.onResume = function()
JPushPlugin.prototype.onPause = function()
#####平台
android
##### 参数说明
-
##### 返回值
#### API - reportNotificationOpened
用于上报用户的通知栏被打开,或者用于上报用户自定义消息被展示等客户端需要统计的事件。
##### 接口定义
JPushPlugin.prototype.reportNotificationOpened = function(msgID)
#####平台
android
##### 参数说明
-
##### 返回值
#### API - openNotificationInAndroidCallback
当点击android手机的通知栏进入应用程序时,会调用这个函数,这个函数不需要主动调用,是作为回调函数来用的
##### 接口定义
JPushPlugin.prototype.openNotificationInAndroidCallback = function(data)
#####平台
android
##### 参数说明
- data js字符串
##### 返回值
+27 -1
View File
@@ -26,6 +26,27 @@
console.log(exception) 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) { var onGetRegistradionID = function(data) {
try{ try{
console.log("JPushPlugin:registrationID is "+data) console.log("JPushPlugin:registrationID is "+data)
@@ -39,6 +60,8 @@
var initiateUI = function(){ var initiateUI = function(){
try{ try{
window.plugins.jPushPlugin.init();
window.plugins.jPushPlugin.setDebugMode(true);
window.plugins.jPushPlugin.getRegistrationID(onGetRegistradionID); window.plugins.jPushPlugin.getRegistrationID(onGetRegistradionID);
// var extras={"name":"json"}; // var extras={"name":"json"};
// window.plugins.jPushPlugin.addLocalNotification(1,"hh","ln",1111,1000*60,extras); // window.plugins.jPushPlugin.addLocalNotification(1,"hh","ln",1111,1000*60,extras);
@@ -89,8 +112,11 @@
} }
}) })
} }
document.addEventListener("jpush.receiveNotification", onReceiveNotification, false);
document.addEventListener("jpush.setTagsWithAlias", onTagsWithAlias, false); document.addEventListener("jpush.setTagsWithAlias", onTagsWithAlias, false);
document.addEventListener("deviceready", onDeviceReady, false); document.addEventListener("deviceready", onDeviceReady, false);
document.addEventListener("jpush.openNotification", onOpenNotification, false);
</script> </script>
</head> </head>
<body> <body>
+4 -4
View File
@@ -29,7 +29,7 @@
<source-file src="src/ios/Plugins/JPushPlugin.m"/> <source-file src="src/ios/Plugins/JPushPlugin.m"/>
<header-file src="src/ios/lib/APService.h" /> <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" /> <resource-file src="src/ios/PushConfig.plist" />
@@ -155,9 +155,9 @@
<meta-data android:name="JPUSH_CHANNEL" android:value="developer-default"/> <meta-data android:name="JPUSH_CHANNEL" android:value="developer-default"/>
<meta-data android:name="JPUSH_APPKEY" android:value="your appkey"/> <meta-data android:name="JPUSH_APPKEY" android:value="your appkey"/>
</config-file> </config-file>
<source-file src="src/android/jpush-sdk-release1.7.2.jar" target-dir="libs"/> <source-file src="src/android/jpush-sdk-release1.7.3.jar" target-dir="libs"/>
<source-file src="src/android/armeabi/libjpush172.so" target-dir="libs/armeabi"/> <source-file src="src/android/armeabi/libjpush173.so" target-dir="libs/armeabi"/>
<source-file src="src/android/armeabi-v7a/libjpush172.so" target-dir="libs/armeabi-v7a"/> <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/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/MyReceiver.java" target-dir="src/cn/jpush/phonegap"/>
<source-file src="src/android/test_notification_layout.xml" target-dir="res/layout"/> <source-file src="src/android/test_notification_layout.xml" target-dir="res/layout"/>
+38 -3
View File
@@ -48,7 +48,10 @@ public class JPushPlugin extends CordovaPlugin {
"clearAllNotification", "clearAllNotification",
"addLocalNotification", "addLocalNotification",
"removeLocalNotification", "removeLocalNotification",
"clearLocalNotifications"); "clearLocalNotifications",
"onResume",
"onPause",
"reportNotificationOpened");
private ExecutorService threadPool = Executors.newFixedThreadPool(1); private ExecutorService threadPool = Executors.newFixedThreadPool(1);
private static JPushPlugin instance; private static JPushPlugin instance;
@@ -75,7 +78,12 @@ public class JPushPlugin extends CordovaPlugin {
data.put("message", message); data.put("message", message);
JSONObject jExtras = new JSONObject(); JSONObject jExtras = new JSONObject();
for(Entry<String,Object> entry:extras.entrySet()){ for(Entry<String,Object> entry:extras.entrySet()){
jExtras.put(entry.getKey(),entry.getValue()); 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) if(jExtras.length()>0)
{ {
@@ -94,7 +102,12 @@ public class JPushPlugin extends CordovaPlugin {
data.put("alert", alert); data.put("alert", alert);
JSONObject jExtras = new JSONObject(); JSONObject jExtras = new JSONObject();
for(Entry<String,Object> entry:extras.entrySet()){ for(Entry<String,Object> entry:extras.entrySet()){
jExtras.put(entry.getKey(),entry.getValue()); 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) if(jExtras.length()>0)
{ {
@@ -131,6 +144,11 @@ public class JPushPlugin extends CordovaPlugin {
data.toString()); data.toString());
try { try {
instance.webView.sendJavascript(js); instance.webView.sendJavascript(js);
String jsEvent=String
.format("cordova.fireDocumentEvent('jpush.openNotification',%s)",
data.toString());
instance.webView.sendJavascript(jsEvent);
} catch (NullPointerException e) { } catch (NullPointerException e) {
} catch (Exception e) { } catch (Exception e) {
@@ -247,6 +265,23 @@ public class JPushPlugin extends CordovaPlugin {
String regID= JPushInterface.getRegistrationID(this.cordova.getActivity().getApplicationContext()); String regID= JPushInterface.getRegistrationID(this.cordova.getActivity().getApplicationContext());
callbackContext.success(regID); 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) { void setTags(JSONArray data, CallbackContext callbackContext) {
Binary file not shown.
Binary file not shown.
+2
View File
@@ -8,6 +8,8 @@
#import <Cordova/CDV.h> #import <Cordova/CDV.h>
#define kJPushPluginReceiveNotification @"JPushPluginReceiveNofication"
@interface JPushPlugin : CDVPlugin{ @interface JPushPlugin : CDVPlugin{
} }
+23 -2
View File
@@ -19,6 +19,12 @@
selector:@selector(networkDidReceiveMessage:) selector:@selector(networkDidReceiveMessage:)
name:kJPFNetworkDidReceiveMessageNotification name:kJPFNetworkDidReceiveMessageNotification
object:nil]; object:nil];
[defaultCenter addObserver:self
selector:@selector(networkDidReceiveNotification:)
name:kJPushPluginReceiveNotification
object:nil];
} }
return self; return self;
@@ -194,13 +200,13 @@
- (void)networkDidReceiveMessage:(NSNotification *)notification { - (void)networkDidReceiveMessage:(NSNotification *)notification {
NSDictionary *userInfo = [notification userInfo]; NSDictionary *userInfo = [notification userInfo];
NSLog(@"%@",userInfo); //NSLog(@"%@",userInfo);
NSError *error; NSError *error;
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:userInfo options:0 error:&error]; NSData *jsonData = [NSJSONSerialization dataWithJSONObject:userInfo options:0 error:&error];
NSString *jsonString = [[NSString alloc]initWithData:jsonData encoding:NSUTF8StringEncoding]; NSString *jsonString = [[NSString alloc]initWithData:jsonData encoding:NSUTF8StringEncoding];
NSLog(@"%@",jsonString); //NSLog(@"%@",jsonString);
dispatch_async(dispatch_get_main_queue(), ^{ dispatch_async(dispatch_get_main_queue(), ^{
@@ -210,4 +216,19 @@
} }
-(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 @end
+1 -1
View File
@@ -4,7 +4,7 @@
// //
// Created by JPush on 12-8-15. // Created by JPush on 12-8-15.
// Copyright (c) 2012年 HXHG. All rights reserved. // Copyright (c) 2012年 HXHG. All rights reserved.
// Version: 1.8.1 // Version: 1.8.2
@class CLRegion; @class CLRegion;
@class UILocalNotification; @class UILocalNotification;
+20
View File
@@ -149,6 +149,7 @@ JPushPlugin.prototype.receiveMessageInAndroidCallback = function(data){
console.log("JPushPlugin:pushCallback "+exception); console.log("JPushPlugin:pushCallback "+exception);
} }
} }
// //
JPushPlugin.prototype.openNotificationInAndroidCallback = function(data){ JPushPlugin.prototype.openNotificationInAndroidCallback = function(data){
try{ try{
@@ -253,6 +254,25 @@ JPushPlugin.prototype.clearLocalNotifications = function(){
this.call_native("clearLocalNotifications",data,null); 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);
}
}
JPushPlugin.prototype.reportNotificationOpened = function(msgID){
if(device.platform == "Android") {
this.call_native("reportNotificationOpened",[msgID],null);
}
}
//iOS single //iOS single