mirror of
https://github.com/jpush/jpush-phonegap-plugin.git
synced 2025-02-20 20:22:50 +08:00
Merge branch 'dev'
This commit is contained in:
commit
adb385a90b
@ -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 收到应用内消息的回调函数(请注意和通知的区别),该函数不需要主动调用
|
||||
|
@ -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",
|
||||
|
@ -2,7 +2,7 @@
|
||||
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
id="cn.jpush.phonegap.JPushPlugin"
|
||||
version="2.1.5">
|
||||
version="2.1.6">
|
||||
|
||||
<name>JPush Plugin</name>
|
||||
<description>JPush for cordova plugin</description>
|
||||
|
@ -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<String, Object> extras) {
|
||||
JSONObject data = new JSONObject();
|
||||
|
@ -60,10 +60,11 @@
|
||||
|
||||
/*
|
||||
* 以下为js中可监听到的事件
|
||||
* jpush.openNotification 点击推送消息唤醒或启动app
|
||||
* jpush.openNotification 点击推送消息启动或唤醒app
|
||||
* jpush.setTagsWithAlias 设置标签、别名完成
|
||||
* jpush.receiveMessage 收到自定义消息
|
||||
* jpush.receiveNotification 前台收到推送消息
|
||||
* jpush.receiveNotification 前台收到推送
|
||||
* jpush.backgoundNotification 后台收到推送
|
||||
*/
|
||||
|
||||
@end
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user