mirror of
https://github.com/jpush/jpush-phonegap-plugin.git
synced 2026-02-19 00:07:08 +08:00
Compare commits
19 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e66336f670 | ||
|
|
2797bdd0e7 | ||
|
|
a197975d03 | ||
|
|
27c4fe7b26 | ||
|
|
aae9e8314a | ||
|
|
7d489c7f20 | ||
|
|
c3cfa01e60 | ||
|
|
27ebdd6809 | ||
|
|
e945bcf53d | ||
|
|
cc858c2464 | ||
|
|
1b93f5e026 | ||
|
|
46e0c1879c | ||
|
|
fe7c52f2c9 | ||
|
|
f217eda463 | ||
|
|
95fc690dd3 | ||
|
|
260c298f6b | ||
|
|
7c1c29a7ec | ||
|
|
0aed054039 | ||
|
|
95194695fe |
131
README.md
131
README.md
@@ -46,7 +46,13 @@
|
||||
|
||||
在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{
|
||||
@@ -86,6 +92,9 @@
|
||||
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
|
||||
// Required
|
||||
[APService handleRemoteNotification:userInfo];
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:kJPushPluginReceiveNotification
|
||||
object:userInfo];
|
||||
|
||||
}
|
||||
|
||||
###Android 手工安装###
|
||||
@@ -487,18 +496,56 @@ iOS
|
||||
|
||||
用于iOS收到应用内消息的回调函数(请注意和通知的区别),该函数不需要主动调用
|
||||
|
||||
##### 使用平台
|
||||
##### 接口定义
|
||||
|
||||
JPushPlugin.prototype.receiveMessageIniOSCallback = function(data)
|
||||
|
||||
|
||||
#####平台
|
||||
iOS
|
||||
|
||||
##### 参数说明
|
||||
#####参数说明
|
||||
|
||||
- data 是一个js字符串使用如下代码解析,js具体key根据应用内消息来确定
|
||||
|
||||
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
|
||||
@@ -719,26 +766,7 @@ android
|
||||
|
||||
#### API - receiveMessageInAndroidCallback
|
||||
|
||||
用于iOS收到应用内消息的回调函数(请注意和通知的区别),该函数不需要主动调用
|
||||
|
||||
##### 接口定义
|
||||
|
||||
JPushPlugin.prototype.receiveMessageInAndroidCallback = function(data)
|
||||
|
||||
|
||||
#####平台
|
||||
android
|
||||
|
||||
##### 参数说明
|
||||
|
||||
- data 接收到的js字符串
|
||||
|
||||
##### 返回值
|
||||
无
|
||||
|
||||
#### API - receiveMessageInAndroidCallback
|
||||
|
||||
用于iOS收到应用内消息的回调函数(请注意和通知的区别),该函数不需要主动调用
|
||||
用于android收到应用内消息的回调函数(请注意和通知的区别),该函数不需要主动调用
|
||||
|
||||
##### 接口定义
|
||||
|
||||
@@ -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字符串
|
||||
|
||||
##### 返回值
|
||||
无
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -26,6 +26,27 @@
|
||||
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("JPushPlugin:registrationID is "+data)
|
||||
@@ -39,6 +60,8 @@
|
||||
var initiateUI = function(){
|
||||
|
||||
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);
|
||||
@@ -89,8 +112,11 @@
|
||||
}
|
||||
})
|
||||
}
|
||||
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>
|
||||
|
||||
@@ -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" />
|
||||
|
||||
@@ -155,9 +155,9 @@
|
||||
<meta-data android:name="JPUSH_CHANNEL" android:value="developer-default"/>
|
||||
<meta-data android:name="JPUSH_APPKEY" android:value="your appkey"/>
|
||||
</config-file>
|
||||
<source-file src="src/android/jpush-sdk-release1.7.2.jar" target-dir="libs"/>
|
||||
<source-file src="src/android/armeabi/libjpush172.so" target-dir="libs/armeabi"/>
|
||||
<source-file src="src/android/armeabi-v7a/libjpush172.so" target-dir="libs/armeabi-v7a"/>
|
||||
<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"/>
|
||||
|
||||
@@ -48,7 +48,10 @@ public class JPushPlugin extends CordovaPlugin {
|
||||
"clearAllNotification",
|
||||
"addLocalNotification",
|
||||
"removeLocalNotification",
|
||||
"clearLocalNotifications");
|
||||
"clearLocalNotifications",
|
||||
"onResume",
|
||||
"onPause",
|
||||
"reportNotificationOpened");
|
||||
|
||||
private ExecutorService threadPool = Executors.newFixedThreadPool(1);
|
||||
private static JPushPlugin instance;
|
||||
@@ -75,7 +78,12 @@ public class JPushPlugin extends CordovaPlugin {
|
||||
data.put("message", message);
|
||||
JSONObject jExtras = new JSONObject();
|
||||
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)
|
||||
{
|
||||
@@ -94,7 +102,12 @@ public class JPushPlugin extends CordovaPlugin {
|
||||
data.put("alert", alert);
|
||||
JSONObject jExtras = new JSONObject();
|
||||
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)
|
||||
{
|
||||
@@ -131,6 +144,11 @@ public class JPushPlugin extends CordovaPlugin {
|
||||
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) {
|
||||
@@ -247,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) {
|
||||
|
||||
|
||||
Binary file not shown.
BIN
src/android/jpush-sdk-release1.7.3.jar
Normal file
BIN
src/android/jpush-sdk-release1.7.3.jar
Normal file
Binary file not shown.
@@ -8,6 +8,8 @@
|
||||
|
||||
#import <Cordova/CDV.h>
|
||||
|
||||
#define kJPushPluginReceiveNotification @"JPushPluginReceiveNofication"
|
||||
|
||||
@interface JPushPlugin : CDVPlugin{
|
||||
|
||||
}
|
||||
|
||||
@@ -19,6 +19,12 @@
|
||||
selector:@selector(networkDidReceiveMessage:)
|
||||
name:kJPFNetworkDidReceiveMessageNotification
|
||||
object:nil];
|
||||
|
||||
[defaultCenter addObserver:self
|
||||
selector:@selector(networkDidReceiveNotification:)
|
||||
name:kJPushPluginReceiveNotification
|
||||
object:nil];
|
||||
|
||||
|
||||
}
|
||||
return self;
|
||||
@@ -194,13 +200,13 @@
|
||||
- (void)networkDidReceiveMessage:(NSNotification *)notification {
|
||||
|
||||
NSDictionary *userInfo = [notification userInfo];
|
||||
NSLog(@"%@",userInfo);
|
||||
//NSLog(@"%@",userInfo);
|
||||
|
||||
NSError *error;
|
||||
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:userInfo options:0 error:&error];
|
||||
NSString *jsonString = [[NSString alloc]initWithData:jsonData encoding:NSUTF8StringEncoding];
|
||||
|
||||
NSLog(@"%@",jsonString);
|
||||
//NSLog(@"%@",jsonString);
|
||||
|
||||
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
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
//
|
||||
// Created by JPush on 12-8-15.
|
||||
// Copyright (c) 2012年 HXHG. All rights reserved.
|
||||
// Version: 1.8.1
|
||||
// Version: 1.8.2
|
||||
|
||||
@class CLRegion;
|
||||
@class UILocalNotification;
|
||||
|
||||
Binary file not shown.
@@ -149,6 +149,7 @@ JPushPlugin.prototype.receiveMessageInAndroidCallback = function(data){
|
||||
console.log("JPushPlugin:pushCallback "+exception);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
JPushPlugin.prototype.openNotificationInAndroidCallback = function(data){
|
||||
try{
|
||||
@@ -253,6 +254,25 @@ JPushPlugin.prototype.clearLocalNotifications = function(){
|
||||
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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user