Merge branch 'dev'

This commit is contained in:
pikacode 2017-03-27 16:32:53 +08:00
commit 78e2e9736e
9 changed files with 67 additions and 40 deletions

View File

@ -14,6 +14,18 @@
- [本地通知](#本地通知)
- [富媒体页面 JavaScript 回调 API](#富媒体页面-javascript-回调-api)
## 注册成功事件
### jpush.receiveRegistrationId
集成了 JPush SDK 的应用程序在第一次成功注册到 JPush 服务器时JPush 服务器会给客户端返回一个唯一的该设备的标识 - RegistrationID。
就会触发这个事件(注意只有第一次会触发该事件,之后如果想要取到 registrationId可以直接调用 *getRegistrationID* 方法)。
#### 代码示例
```Javascript
document.addEventListener('jpush.receiveRegistrationId', function (event) {
console.log(event.registrationId)
}, false)
```
## 接收通知时获得通知的内容
- 内容:
@ -55,7 +67,6 @@
- true 显示集成日志。
- false 不显示集成日志。
## 接收消息和点击通知事件
### API - receiveMessageInAndroidCallback
@ -82,7 +93,6 @@
- data: js 字符串。
## 统计分析
### API - onResume / onPause

View File

@ -1,6 +1,6 @@
{
"name": "jpush-phonegap-plugin",
"version": "3.1.1",
"version": "3.1.2",
"description": "JPush for cordova plugin",
"cordova": {
"id": "jpush-phonegap-plugin",
@ -29,7 +29,7 @@
],
"peerDependencies": {
"cordova-plugin-device": ">=1.0.0",
"cordova-plugin-jcore": "1.1.0"
"cordova-plugin-jcore": "1.1.1"
},
"author": "JiGuang",
"license": "MIT",

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="jpush-phonegap-plugin"
version="3.1.1">
version="3.1.2">
<name>JPush Plugin</name>
<description>JPush for cordova plugin</description>
@ -186,7 +186,7 @@
<meta-data android:name="JPUSH_APPKEY" android:value="$APP_KEY" />
</config-file>
<source-file src="src/android/libs/jpush-android_v3.0.1.jar" target-dir="libs" />
<source-file src="src/android/libs/jpush-android_v3.0.3.jar" target-dir="libs" />
<source-file src="src/android/MyReceiver.java" target-dir="src/cn/jpush/phonegap" />
<source-file src="src/android/JPushPlugin.java" target-dir="src/cn/jpush/phonegap" />

View File

@ -262,6 +262,26 @@ public class JPushPlugin extends CordovaPlugin {
JPushPlugin.notificationAlert = null;
}
static void transmitReceiveRegistrationId(String rId) {
if (instance == null) {
return;
}
JSONObject data = new JSONObject();
try {
data.put("registrationId", rId);
} catch (JSONException e) {
e.printStackTrace();
}
String format = "window.plugins.jPushPlugin.receiveRegistrationIdInAndroidCallback(%s);";
final String js = String.format(format, data.toString());
cordovaActivity.runOnUiThread(new Runnable() {
@Override
public void run() {
instance.webView.loadUrl("javascript:" + js);
}
});
}
@Override
public boolean execute(final String action, final JSONArray data,
final CallbackContext callbackContext) throws JSONException {

View File

@ -1,18 +1,18 @@
package cn.jpush.phonegap;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import cn.jpush.android.api.JPushInterface;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
public class MyReceiver extends BroadcastReceiver {
private static String TAG = "JPushPlugin";
private static final List<String> IGNORED_EXTRAS_KEYS =
Arrays.asList(
"cn.jpush.android.TITLE",
@ -24,18 +24,15 @@ public class MyReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (JPushInterface.ACTION_MESSAGE_RECEIVED.equals(action)) {
if (action.equals(JPushInterface.ACTION_REGISTRATION_ID)) {
String rId = intent.getStringExtra(JPushInterface.EXTRA_REGISTRATION_ID);
JPushPlugin.transmitReceiveRegistrationId(rId);
} else if (action.equals(JPushInterface.ACTION_MESSAGE_RECEIVED)) {
handlingMessageReceive(intent);
} else if (JPushInterface.ACTION_NOTIFICATION_RECEIVED.equals(action)) {
} else if (action.equals(JPushInterface.ACTION_NOTIFICATION_RECEIVED)) {
handlingNotificationReceive(context, intent);
} else if (JPushInterface.ACTION_NOTIFICATION_OPENED.equals(action)) {
} else if (action.equals(JPushInterface.ACTION_NOTIFICATION_OPENED)) {
handlingNotificationOpen(context, intent);
} else if (JPushInterface.ACTION_RICHPUSH_CALLBACK.equals(action)) {
// 当在 HTML 页面中调用 JPushWeb.triggerNativeAction(String params) 方法时触发此方法
// 再进行相关的操作
} else {
Log.d(TAG, "Unhandled intent - " + action);
}
}
@ -46,8 +43,6 @@ public class MyReceiver extends BroadcastReceiver {
}
private void handlingNotificationOpen(Context context, Intent intent) {
Log.i(TAG, "---------------- handlingNotificationOpen");
String title = intent.getStringExtra(JPushInterface.EXTRA_NOTIFICATION_TITLE);
JPushPlugin.openNotificationTitle = title;
@ -60,15 +55,13 @@ public class MyReceiver extends BroadcastReceiver {
JPushPlugin.transmitNotificationOpen(title, alert, extras);
Intent launch = context.getPackageManager().getLaunchIntentForPackage(
context.getPackageName());
context.getPackageName());
launch.addCategory(Intent.CATEGORY_LAUNCHER);
launch.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP);
context.startActivity(launch);
}
private void handlingNotificationReceive(Context context, Intent intent) {
Log.i(TAG, "---------------- handlingNotificationReceive");
Intent launch = context.getPackageManager().getLaunchIntentForPackage(
context.getPackageName());
launch.addCategory(Intent.CATEGORY_LAUNCHER);
@ -99,5 +92,4 @@ public class MyReceiver extends BroadcastReceiver {
}
return extrasMap;
}
}

Binary file not shown.

View File

@ -28,29 +28,27 @@
return [self init_plus];
}
NSDictionary *_launchOptions;
-(void)fireOpenNotification:(NSTimer*)timer{
if (SharedJPushPlugin) {
[JPushPlugin fireDocumentEvent:JPushDocumentEvent_OpenNotification jsString:[timer.userInfo toJsonString]];
[timer invalidate];
}
}
NSDictionary *_launchOptions;
-(void)applicationDidLaunch:(NSNotification *)notification{
if (notification) {
if (notification.userInfo) {
NSDictionary *userInfo1 = [notification.userInfo valueForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
if (userInfo1.count > 0) {
[NSTimer scheduledTimerWithTimeInterval:0.1 repeats:YES block:^(NSTimer * _Nonnull timer) {
if (SharedJPushPlugin) {
[JPushPlugin fireDocumentEvent:JPushDocumentEvent_OpenNotification jsString:[userInfo1 toJsonString]];
[timer invalidate];
}
}];
[NSTimer scheduledTimerWithTimeInterval:0.01 target:self selector:@selector(fireOpenNotification:) userInfo:userInfo1 repeats:YES];
}
NSDictionary *userInfo2 = [notification.userInfo valueForKey:UIApplicationLaunchOptionsLocalNotificationKey];
if (userInfo2.count > 0) {
[NSTimer scheduledTimerWithTimeInterval:0.1 repeats:YES block:^(NSTimer * _Nonnull timer) {
if (SharedJPushPlugin) {
[JPushPlugin fireDocumentEvent:JPushDocumentEvent_OpenNotification jsString:[userInfo2 toJsonString]];
[timer invalidate];
}
}];
[NSTimer scheduledTimerWithTimeInterval:0.01 target:self selector:@selector(fireOpenNotification:) userInfo:userInfo2 repeats:YES];
}
}
[JPUSHService setDebugMode];
@ -64,7 +62,6 @@ NSDictionary *_launchOptions;
if (![delay boolValue]) {
[self startJPushSDK];
}
}
}

View File

@ -217,6 +217,14 @@ JPushPlugin.prototype.setCustomPushNotificationBuilder = function () {
}
}
JPushPlugin.prototype.receiveRegistrationIdInAndroidCallback = function (data) {
if (device.platform === 'Android') {
data = JSON.stringify(data)
var event = JSON.parse(data)
cordova.fireDocumentEvent('jpush.receiveRegistrationId', event);
}
}
JPushPlugin.prototype.receiveMessageInAndroidCallback = function (data) {
data = JSON.stringify(data)
console.log('JPushPlugin:receiveMessageInAndroidCallback: ' + data)