mirror of
https://github.com/jpush/jpush-phonegap-plugin.git
synced 2026-04-19 00:03:45 +08:00
Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 07c9b2b945 | |||
| 8811dfc002 |
@@ -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)
|
## 获取集成日志(同时适用于 iOS)
|
||||||
|
|
||||||
### API - setDebugMode
|
### API - setDebugMode
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
# 通用 API 说明(同时适用于 Android 和 iOS 系统)
|
# 通用 API 说明(同时适用于 Android 和 iOS 系统)
|
||||||
|
|
||||||
|
- [注册成功事件](#注册成功事件)
|
||||||
- [停止与恢复推送服务](#停止与恢复推送服务)
|
- [停止与恢复推送服务](#停止与恢复推送服务)
|
||||||
- [获取 RegistrationID](#获取-registrationid)
|
- [获取 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 - init
|
||||||
|
|
||||||
调用此 API,用来开启 JPush SDK 提供的推送服务。
|
调用此 API,用来开启 JPush SDK 提供的推送服务。
|
||||||
|
|||||||
@@ -155,7 +155,12 @@ NSDictionary *_launchOptions;
|
|||||||
}
|
}
|
||||||
|
|
||||||
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification {
|
- (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 {
|
- (void)applicationWillEnterForeground:(UIApplication *)application {
|
||||||
|
|||||||
@@ -79,6 +79,10 @@
|
|||||||
selector:@selector(networkDidReceiveMessage:)
|
selector:@selector(networkDidReceiveMessage:)
|
||||||
name:kJPFNetworkDidReceiveMessageNotification
|
name:kJPFNetworkDidReceiveMessageNotification
|
||||||
object:nil];
|
object:nil];
|
||||||
|
[[NSNotificationCenter defaultCenter] addObserver:self
|
||||||
|
selector:@selector(receiveLocalNotification:)
|
||||||
|
name:JPushDocumentEvent_ReceiveLocalNotification
|
||||||
|
object:nil];
|
||||||
}
|
}
|
||||||
|
|
||||||
+(void)fireDocumentEvent:(NSString*)eventName jsString:(NSString*)jsString{
|
+(void)fireDocumentEvent:(NSString*)eventName jsString:(NSString*)jsString{
|
||||||
@@ -347,14 +351,50 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
-(void)setLocalNotification:(CDVInvokedUrlCommand*)command{
|
-(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];
|
||||||
|
|
||||||
NSDate *date = [NSDate dateWithTimeIntervalSinceNow:[[command argumentAtIndex:0] intValue]];
|
|
||||||
NSString *alert = [command argumentAtIndex:1];
|
NSString *alert = [command argumentAtIndex:1];
|
||||||
NSNumber *badge = [command argumentAtIndex:2];
|
NSNumber *badge = [command argumentAtIndex:2];
|
||||||
NSString *idKey = [command argumentAtIndex:3];
|
NSString *idKey = [command argumentAtIndex:3];
|
||||||
NSDictionary *dict = [command argumentAtIndex:4];
|
NSDictionary *userInfo = [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{
|
-(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
|
@end
|
||||||
|
|||||||
Reference in New Issue
Block a user