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 收到应用内消息的回调函数(请注意和通知的区别),该函数不需要主动调用 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 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(); 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