mirror of
https://github.com/jpush/jpush-phonegap-plugin.git
synced 2025-01-31 22:42:51 +08:00
Merge branch 'dev'
This commit is contained in:
commit
494df2e527
@ -1,7 +1,7 @@
|
||||
# JPush PhoneGap / Cordova Plugin
|
||||
|
||||
[![Build Status](https://travis-ci.org/jpush/jpush-phonegap-plugin.svg?branch=master)](https://travis-ci.org/jpush/jpush-phonegap-plugin)
|
||||
[![release](https://img.shields.io/badge/release-3.2.8-blue.svg)](https://github.com/jpush/jpush-phonegap-plugin/releases)
|
||||
[![release](https://img.shields.io/badge/release-3.2.9-blue.svg)](https://github.com/jpush/jpush-phonegap-plugin/releases)
|
||||
[![platforms](https://img.shields.io/badge/platforms-iOS%7CAndroid-lightgrey.svg)](https://github.com/jpush/jpush-phonegap-plugin)
|
||||
[![weibo](https://img.shields.io/badge/weibo-JPush-blue.svg)](http://weibo.com/jpush?refer_flag=1001030101_&is_all=1)
|
||||
|
||||
|
@ -9,19 +9,6 @@
|
||||
- [设置保留最近通知条数](#设置保留最近通知条数)
|
||||
- [本地通知](#本地通知)
|
||||
|
||||
## 注册成功事件
|
||||
### jpush.receiveRegistrationId
|
||||
集成了 JPush SDK 的应用程序在第一次成功注册到 JPush 服务器时,JPush 服务器会给客户端返回一个唯一的该设备的标识 - RegistrationID。
|
||||
就会触发这个事件(注意只有第一次会触发该事件,之后如果想要取到 registrationId,可以直接调用 *getRegistrationID* 方法)。
|
||||
|
||||
#### 代码示例
|
||||
|
||||
```js
|
||||
document.addEventListener('jpush.receiveRegistrationId', function (event) {
|
||||
console.log(event.registrationId)
|
||||
}, false)
|
||||
```
|
||||
|
||||
## 获取集成日志(同时适用于 iOS)
|
||||
|
||||
### API - setDebugMode
|
||||
@ -103,7 +90,7 @@ window.JPush.setPushTime(days, startHour, endHour)
|
||||
#### 参数说明
|
||||
|
||||
- days: 数组,0 表示星期天,1 表示星期一,以此类推(7天制,数组中值的范围为 0 到 6 )。
|
||||
数组的值为 null, 表示任何时间都可以收到消息和通知,数组的 size 为 0,则表示任何时间都收不到消息和通知。
|
||||
数组的值为 null, 表示任何时间都可以收到消息和通知,数组的 size 为 0,则表示任何时间都收不到消息和通知。
|
||||
- startHour: 整形,允许推送的开始时间 (24 小时制:startHour 的范围为 0 到 23)。
|
||||
- endHour: 整形,允许推送的结束时间 (24 小时制:endHour 的范围为 0 到 23)。
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
# 通用 API 说明(同时适用于 Android 和 iOS 系统)
|
||||
|
||||
- [注册成功事件](#注册成功事件)
|
||||
- [停止与恢复推送服务](#停止与恢复推送服务)
|
||||
- [获取 RegistrationID](#获取-registrationid)
|
||||
- [设置别名与标签](#设置别名与标签)
|
||||
@ -8,7 +9,23 @@
|
||||
- [获取自定义消息推送内容](#获取自定义消息推送内容)
|
||||
- [判断系统设置中是否允许当前应用推送](#判断系统设置中是否允许当前应用推送)
|
||||
|
||||
## 注册成功事件
|
||||
|
||||
### jpush.receiveRegistrationId
|
||||
|
||||
集成了 JPush SDK 的应用程序在第一次成功注册到 JPush 服务器时,JPush 服务器会给客户端返回一个唯一的该设备的标识 - RegistrationID。
|
||||
就会触发这个事件(注意只有第一次会触发该事件,之后如果想要取到 registrationId,可以直接调用 *getRegistrationID* 方法)。
|
||||
|
||||
#### 代码示例
|
||||
|
||||
```js
|
||||
document.addEventListener('jpush.receiveRegistrationId', function (event) {
|
||||
console.log(event.registrationId)
|
||||
}, false)
|
||||
```
|
||||
|
||||
## 停止与恢复推送服务
|
||||
|
||||
### API - init
|
||||
|
||||
调用此 API,用来开启 JPush SDK 提供的推送服务。
|
||||
@ -545,4 +562,4 @@ window.JPush.getUserNotificationSettings(function(result) {
|
||||
} else if(result > 0) {
|
||||
// 系统设置中打开了应用推送。
|
||||
})
|
||||
```
|
||||
```
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "jpush-phonegap-plugin",
|
||||
"version": "3.2.8",
|
||||
"version": "3.2.9",
|
||||
"description": "JPush for cordova plugin",
|
||||
"cordova": {
|
||||
"id": "jpush-phonegap-plugin",
|
||||
|
@ -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.2.8">
|
||||
version="3.2.9">
|
||||
|
||||
<name>JPush</name>
|
||||
<description>JPush for cordova plugin</description>
|
||||
|
@ -155,7 +155,12 @@ NSDictionary *_launchOptions;
|
||||
}
|
||||
|
||||
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification {
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:JPushDocumentEvent_ReceiveLocalNotification object:notification.userInfo];
|
||||
NSDictionary* localNotificationEvent = @{@"content":notification.alertBody,
|
||||
@"badge": @(notification.applicationIconBadgeNumber),
|
||||
@"extras":notification.userInfo,
|
||||
};
|
||||
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:JPushDocumentEvent_ReceiveLocalNotification object:localNotificationEvent];
|
||||
}
|
||||
|
||||
- (void)applicationWillEnterForeground:(UIApplication *)application {
|
||||
|
@ -79,6 +79,10 @@
|
||||
selector:@selector(networkDidReceiveMessage:)
|
||||
name:kJPFNetworkDidReceiveMessageNotification
|
||||
object:nil];
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self
|
||||
selector:@selector(receiveLocalNotification:)
|
||||
name:JPushDocumentEvent_ReceiveLocalNotification
|
||||
object:nil];
|
||||
}
|
||||
|
||||
+(void)fireDocumentEvent:(NSString*)eventName jsString:(NSString*)jsString{
|
||||
@ -347,14 +351,50 @@
|
||||
}
|
||||
|
||||
-(void)setLocalNotification:(CDVInvokedUrlCommand*)command{
|
||||
NSLog(@"ios 10 after please use UNNotificationRequest to set local notification, see apple doc to learn more");
|
||||
NSNumber *delay = [command argumentAtIndex:0];
|
||||
NSString *alert = [command argumentAtIndex:1];
|
||||
NSNumber *badge = [command argumentAtIndex:2];
|
||||
NSString *idKey = [command argumentAtIndex:3];
|
||||
NSDictionary *userInfo = [command argumentAtIndex:4];
|
||||
|
||||
NSDate *date = [NSDate dateWithTimeIntervalSinceNow:[[command argumentAtIndex:0] intValue]];
|
||||
NSString *alert = [command argumentAtIndex:1];
|
||||
NSNumber *badge = [command argumentAtIndex:2];
|
||||
NSString *idKey = [command argumentAtIndex:3];
|
||||
NSDictionary *dict = [command argumentAtIndex:4];
|
||||
[JPUSHService setLocalNotification:date alertBody:alert badge:badge.intValue alertAction:nil identifierKey:idKey userInfo:dict soundName:nil];
|
||||
JPushNotificationContent *content = [[JPushNotificationContent alloc] init];
|
||||
|
||||
if (alert) {
|
||||
content.body = alert;
|
||||
}
|
||||
|
||||
if (badge) {
|
||||
content.badge = badge;
|
||||
}
|
||||
|
||||
if (userInfo) {
|
||||
content.userInfo = userInfo;
|
||||
}
|
||||
|
||||
JPushNotificationTrigger *trigger = [[JPushNotificationTrigger alloc] init];
|
||||
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 10.0) {
|
||||
if (delay) {
|
||||
trigger.timeInterval = [delay doubleValue];
|
||||
}
|
||||
} else {
|
||||
if (delay) {
|
||||
trigger.fireDate = [NSDate dateWithTimeIntervalSinceNow:[[command argumentAtIndex:0] intValue]];
|
||||
}
|
||||
}
|
||||
|
||||
JPushNotificationRequest *request = [[JPushNotificationRequest alloc] init];
|
||||
request.content = content;
|
||||
request.trigger = trigger;
|
||||
|
||||
if (idKey) {
|
||||
request.requestIdentifier = idKey;
|
||||
}
|
||||
|
||||
request.completionHandler = ^(id result) {
|
||||
NSLog(@"result");
|
||||
};
|
||||
|
||||
[JPUSHService addNotification:request];
|
||||
}
|
||||
|
||||
-(void)deleteLocalNotificationWithIdentifierKey:(CDVInvokedUrlCommand*)command{
|
||||
@ -503,4 +543,10 @@
|
||||
}
|
||||
}
|
||||
|
||||
-(void)receiveLocalNotification:(NSNotification *)notification {
|
||||
if (notification && notification.object) {
|
||||
[JPushPlugin fireDocumentEvent:JPushDocumentEvent_ReceiveLocalNotification
|
||||
jsString:[notification.object toJsonString]];
|
||||
}
|
||||
}
|
||||
@end
|
||||
|
Loading…
Reference in New Issue
Block a user