From 95c9b121243a5b60c3e5d01c0da07937c051d3b7 Mon Sep 17 00:00:00 2001 From: "E.B" <57380422@qq.com> Date: Fri, 22 Apr 2016 15:44:04 +0800 Subject: [PATCH 1/4] iOS - new feature MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. 增加 jpush.backgroundNotification 事件 2. 重新区分原有事件的触发条件 3. 更新 文档接口说明 --- src/ios/Plugins/JPushPlugin.h | 5 +++-- src/ios/Plugins/JPushPlugin.m | 26 +++++++++++++++----------- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/src/ios/Plugins/JPushPlugin.h b/src/ios/Plugins/JPushPlugin.h index 256b05a..1164636 100644 --- a/src/ios/Plugins/JPushPlugin.h +++ b/src/ios/Plugins/JPushPlugin.h @@ -60,10 +60,11 @@ /* * 以下为js中可监听到的事件 - * jpush.openNotification 点击推送消息唤醒或启动app + * jpush.openNotification 点击推送消息启动或唤醒app * jpush.setTagsWithAlias 设置标签、别名完成 * jpush.receiveMessage 收到自定义消息 - * jpush.receiveNotification 前台收到推送消息 + * jpush.receiveNotification 前台收到推送 + * jpush.backgoundNotification 后台收到推送 */ @end diff --git a/src/ios/Plugins/JPushPlugin.m b/src/ios/Plugins/JPushPlugin.m index 6e78278..32b4ec0 100644 --- a/src/ios/Plugins/JPushPlugin.m +++ b/src/ios/Plugins/JPushPlugin.m @@ -356,29 +356,33 @@ static NSDictionary *_luanchOptions = nil; NSData *jsonData = [NSJSONSerialization dataWithJSONObject:userInfo options:0 error:&error]; NSString *jsonString = [[NSString alloc]initWithData:jsonData encoding:NSUTF8StringEncoding]; - NSLog(@"%ld",(long)[UIApplication sharedApplication].applicationState); switch ([UIApplication sharedApplication].applicationState) { - case UIApplicationStateActive: - { + case UIApplicationStateActive:{ + //前台收到 dispatch_async(dispatch_get_main_queue(), ^{ [self.commandDelegate evalJs:[NSString stringWithFormat:@"cordova.fireDocumentEvent('jpush.receiveNotification',%@)",jsonString]]; }); - } break; - case UIApplicationStateInactive: - case UIApplicationStateBackground: - { + } + case UIApplicationStateInactive:{ + //后台点击 dispatch_async(dispatch_get_main_queue(), ^{ [self.commandDelegate evalJs:[NSString stringWithFormat:@"cordova.fireDocumentEvent('jpush.openNotification',%@)",jsonString]]; }); - + break; } + case UIApplicationStateBackground:{ + //后台收到 + dispatch_async(dispatch_get_main_queue(), ^{ + [self.commandDelegate evalJs:[NSString stringWithFormat:@"cordova.fireDocumentEvent('jpush.backgoundNotification',%@)",jsonString]]; + }); break; + } default: - //do nothing - break; + //do nothing + break; } - + } @end From 1a6800a7b4ac189fb59a702792437d9af1e43cfd Mon Sep 17 00:00:00 2001 From: "E.B" <57380422@qq.com> Date: Fri, 22 Apr 2016 15:53:24 +0800 Subject: [PATCH 2/4] iOS - update API MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. 解决冲突 添加接口 --- API/iOS API.md | 46 ++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 40 insertions(+), 6 deletions(-) diff --git a/API/iOS API.md b/API/iOS API.md index 0491ccc..32593a2 100644 --- a/API/iOS API.md +++ b/API/iOS API.md @@ -4,8 +4,9 @@ - [获取 RegistrationID](#获取-registrationid) - [别名与标签](#别名与标签) - [获取 APNS 推送内容](#获取-apns-推送内容) - - [点击推送获取](#点击推送获取) - - [前台获取](#前台获取) + - [点击推送通知](#点击推送通知) + - [前台收到推送](#前台收到推送) + - [后台收到推送](#后台收到推送) - [获取自定义消息内容](#获取自定义消息内容) - [设置Badge](#设置badge) - [本地通知](#本地通知) @@ -194,11 +195,11 @@ JPush SDK 会以广播的形式发送 RegistrationID 到应用程序。 ## 获取 APNS 推送内容 -### 点击推送获取 +### 点击推送通知 #### event - jpush.openNotification -点击通知进入应用程序时会出发改事件。 +点击通知启动或唤醒应用程序时会出发该事件 #### 代码示例 @@ -227,11 +228,11 @@ JPush SDK 会以广播的形式发送 RegistrationID 到应用程序。 "_j_msgid":154604475 } -### 前台获取 +### 前台收到推送 #### event - jpush.receiveNotification -应用程序处于前台时会触发该事件。 +应用程序处于前台时收到推送会触发该事件 #### 代码示例 @@ -260,6 +261,39 @@ JPush SDK 会以广播的形式发送 RegistrationID 到应用程序。 "_j_msgid":154604475 } +### 后台收到推送 + +#### event - jpush.backgroundNotification + +应用程序处于后台时收到推送会触发该事件,可以在后台执行一段代码。具体配置参考 [iOS 7 Background Remote Notification](http://docs.jpush.io/client/ios_tutorials/#ios-7-background-remote-notification) + +#### 代码示例 + +- 在你需要接收通知的的 js 文件中加入: + + document.addEventListener("jpush.backgroundNotification", onBackgroundNotification, false); + +- onBackgroundNotification 需要这样写: + + var onBackgroundNotification = function(event) { + var alertContent; + alertContent = event.aps.alert; + alert("open Notificaiton:" + alertContent); + } + ++ event 举例 + + { + "aps":{ + "badge":1, + "sound":"default", + "alert":"今天去哪儿" + }, + "key1":"value1", + "key2":"value2", + "_j_msgid":154604475 + } + #### API - receiveMessageIniOSCallback 用于 iOS 收到应用内消息的回调函数(请注意和通知的区别),该函数不需要主动调用 From 5fb1a440c4203b8553e1f7859d0c59620dbfefc5 Mon Sep 17 00:00:00 2001 From: Hevin <328066446@qq.com> Date: Mon, 25 Apr 2016 14:03:57 +0800 Subject: [PATCH 3/4] fix bug MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修复应用在后台点击通知无法触发点击事件的 bug。 --- src/android/JPushPlugin.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/android/JPushPlugin.java b/src/android/JPushPlugin.java index 95e797a..ee23659 100644 --- a/src/android/JPushPlugin.java +++ b/src/android/JPushPlugin.java @@ -131,6 +131,13 @@ public class JPushPlugin extends CordovaPlugin { } } + @Override + public void onDestroy() { + super.onDestroy(); + cordovaActivity = null; + instance = null; + } + private static JSONObject getMessageObject(String message, Map extras) { JSONObject data = new JSONObject(); From 76b3014417b60959b7f8aa11871fb3d8ac1c4b63 Mon Sep 17 00:00:00 2001 From: Hevin <328066446@qq.com> Date: Mon, 25 Apr 2016 14:33:45 +0800 Subject: [PATCH 4/4] v 2.1.4 --- package.json | 2 +- plugin.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 9583a35..6454456 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "jpush-phonegap-plugin", - "version": "2.1.5", + "version": "2.1.6", "description": "JPush for cordova plugin", "cordova": { "id": "cn.jpush.phonegap.JPushPlugin", diff --git a/plugin.xml b/plugin.xml index 88b38a1..29e03bb 100644 --- a/plugin.xml +++ b/plugin.xml @@ -2,7 +2,7 @@ + version="2.1.6"> JPush Plugin JPush for cordova plugin