mirror of
https://github.com/jpush/jpush-phonegap-plugin.git
synced 2026-04-19 00:03:45 +08:00
Compare commits
15 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4b929a8e2e | ||
|
|
d3e2e1a5d7 | ||
|
|
001ab96283 | ||
|
|
1314d33c62 | ||
|
|
22b6d9a006 | ||
|
|
0cbedb412c | ||
|
|
fbd9d63590 | ||
|
|
184ee01d1d | ||
|
|
14a40c6572 | ||
|
|
fefaaea14f | ||
|
|
d2f9959ae1 | ||
|
|
3129165d3f | ||
|
|
66932a8bc8 | ||
|
|
07c9b2b945 | ||
|
|
8811dfc002 |
@@ -1,7 +1,7 @@
|
||||
# JPush PhoneGap / Cordova Plugin
|
||||
|
||||
[](https://travis-ci.org/jpush/jpush-phonegap-plugin)
|
||||
[](https://github.com/jpush/jpush-phonegap-plugin/releases)
|
||||
[](https://github.com/jpush/jpush-phonegap-plugin/releases)
|
||||
[](https://github.com/jpush/jpush-phonegap-plugin)
|
||||
[](http://weibo.com/jpush?refer_flag=1001030101_&is_all=1)
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
- 或下载到本地安装:
|
||||
|
||||
```shell
|
||||
cordova plugin add Your_Plugin_Path --variable APP_KEY=your_jpush_appkey
|
||||
cordova plugin add Your_Plugin_Path --variable APP_KEY=your_jpush_appkey
|
||||
```
|
||||
|
||||
> 在使用 Xcode 8 调试 iOS 项目时,需要先在项目配置界面的 Capabilities 中打开 Push Notifications 开关。
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
# Android API 简介
|
||||
|
||||
- [注册成功事件](#注册成功事件)
|
||||
- [获取集成日志(同时适用于 iOS)](#获取集成日志同时适用于-ios)
|
||||
- [清除通知](#清除通知)
|
||||
- [设置允许推送时间](#设置允许推送时间)
|
||||
- [设置通知静默时间](#设置通知静默时间)
|
||||
@@ -9,19 +7,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 +88,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,15 +1,52 @@
|
||||
# 通用 API 说明(同时适用于 Android 和 iOS 系统)
|
||||
|
||||
- [停止与恢复推送服务](#停止与恢复推送服务)
|
||||
- [注册成功事件](#注册成功事件)
|
||||
- [jpush.receiveRegistrationId](#jpushreceiveregistrationid)
|
||||
- [初始化、停止与恢复推送服务](#初始化停止与恢复推送服务)
|
||||
- [init](#init)
|
||||
- [stopPush](#stoppush)
|
||||
- [resumePush](#resumepush)
|
||||
- [isPushStopped](#ispushstopped)
|
||||
- [开启 Debug 模式](#开启-debug-模式)
|
||||
- [setDebugMode](#setdebugmode)
|
||||
- [获取 RegistrationID](#获取-registrationid)
|
||||
- [getRegistrationID](#getregistrationid)
|
||||
- [设置别名与标签](#设置别名与标签)
|
||||
- [setAlias](#setalias)
|
||||
- [deleteAlias](#deletealias)
|
||||
- [getAlias](#getalias)
|
||||
- [setTags](#settags)
|
||||
- [addTags](#addtags)
|
||||
- [deleteTags](#deletetags)
|
||||
- [cleanTags](#cleantags)
|
||||
- [getAllTags](#getalltags)
|
||||
- [checkTagBindState](#checktagbindstate)
|
||||
- [获取点击通知内容](#获取点击通知内容)
|
||||
- [event - jpush.openNotification](#event---jpushopennotification)
|
||||
- [获取通知内容](#获取通知内容)
|
||||
- [event - jpush.receiveNotification](#event---jpushreceivenotification)
|
||||
- [获取自定义消息推送内容](#获取自定义消息推送内容)
|
||||
- [event - jpush.receiveMessage](#event---jpushreceivemessage)
|
||||
- [判断系统设置中是否允许当前应用推送](#判断系统设置中是否允许当前应用推送)
|
||||
|
||||
## 停止与恢复推送服务
|
||||
### API - init
|
||||
## 注册成功事件
|
||||
|
||||
### jpush.receiveRegistrationId
|
||||
|
||||
集成了 JPush SDK 的应用程序在第一次成功注册到 JPush 服务器时,JPush 服务器会给客户端返回一个唯一的该设备的标识 - Registration ID。
|
||||
此时就会触发这个事件(注意只有第一次会触发该事件,之后如果想要取到 Registration Id,可以直接调用 `getRegistrationID` 方法)。
|
||||
|
||||
#### 代码示例
|
||||
|
||||
```js
|
||||
document.addEventListener('jpush.receiveRegistrationId', function (event) {
|
||||
console.log(event.registrationId)
|
||||
}, false)
|
||||
```
|
||||
|
||||
## 初始化、停止与恢复推送服务
|
||||
|
||||
### init
|
||||
|
||||
调用此 API,用来开启 JPush SDK 提供的推送服务。
|
||||
|
||||
@@ -27,7 +64,7 @@
|
||||
window.JPush.init()
|
||||
```
|
||||
|
||||
### API - stopPush
|
||||
### stopPush
|
||||
|
||||
- Android:
|
||||
- 开发者 App 可以通过调用停止推送服务 API 来停止极光推送服务,当又需要使用极光推送服务时,则必须要调用恢复推送服务 API。
|
||||
@@ -46,7 +83,7 @@ window.JPush.init()
|
||||
window.JPush.stopPush()
|
||||
```
|
||||
|
||||
### API - resumePush
|
||||
### resumePush
|
||||
|
||||
恢复推送服务。调用了此 API 后:
|
||||
|
||||
@@ -62,7 +99,7 @@ window.JPush.stopPush()
|
||||
window.JPush.resumePush()
|
||||
```
|
||||
|
||||
### API - isPushStopped
|
||||
### isPushStopped
|
||||
|
||||
- Android 平台:
|
||||
- 用来检查 Push Service 是否已经被停止。
|
||||
@@ -93,7 +130,7 @@ window.JPush.isPushStopped(function (result) {
|
||||
```
|
||||
|
||||
## 开启 Debug 模式
|
||||
### API - setDebugMode
|
||||
### setDebugMode
|
||||
用于开启 Debug 模式,显示更多的日志信息。
|
||||
|
||||
#### 代码示例
|
||||
@@ -103,11 +140,13 @@ window.JPush.setDebugMode(true)
|
||||
```
|
||||
|
||||
#### 参数说明
|
||||
- isOpen: true,开启 Debug 模式;false,关闭 Debug 模式,不显示错误信息之外的日志信息。
|
||||
|
||||
- true: 开启 Debug 模式;
|
||||
- false: 关闭 Debug 模式,不显示错误信息之外的日志信息。
|
||||
|
||||
## 获取 RegistrationID
|
||||
|
||||
### API - getRegistrationID
|
||||
### getRegistrationID
|
||||
|
||||
RegistrationID 定义:
|
||||
|
||||
@@ -361,7 +400,7 @@ window.JPush.checkTagBindState({ sequence: 1, tag: 'tag1' },
|
||||
|
||||
### event - jpush.openNotification
|
||||
|
||||
点击通知进入应用程序时会出发改事件。
|
||||
点击通知进入应用程序时触发。
|
||||
|
||||
#### 代码示例
|
||||
|
||||
@@ -378,8 +417,6 @@ document.addEventListener("jpush.openNotification", function (event) {
|
||||
}, false)
|
||||
```
|
||||
|
||||
> ps:点击通知后传递的 json object 保存在 window.JPush.openNotification,直接访问即可,字段示例,根据实际推送情况,可能略有差别,请注意。
|
||||
|
||||
- Android:
|
||||
|
||||
```json
|
||||
@@ -418,7 +455,7 @@ document.addEventListener("jpush.openNotification", function (event) {
|
||||
|
||||
### event - jpush.receiveNotification
|
||||
|
||||
收到通知时会触发该事件。
|
||||
收到通知时触发。
|
||||
|
||||
#### 代码示例
|
||||
|
||||
@@ -436,8 +473,6 @@ document.addEventListener("jpush.receiveNotification", function (event) {
|
||||
}, false)
|
||||
```
|
||||
|
||||
> ps:点击通知后传递的 json object 保存在 window.JPush.receiveNotification,直接访问即可,字段示例,根据实际推送情况,可能略有差别,请注意。
|
||||
|
||||
- Android:
|
||||
|
||||
```json
|
||||
@@ -476,7 +511,7 @@ document.addEventListener("jpush.receiveNotification", function (event) {
|
||||
|
||||
### event - jpush.receiveMessage
|
||||
|
||||
收到自定义消息时触发这个事件,推荐使用事件的方式传递。
|
||||
收到自定义消息时触发,推荐使用事件的方式传递。
|
||||
|
||||
但同时保留了 `receiveMessageIniOSCallback` 的回调函数,兼容以前的代码。
|
||||
|
||||
@@ -495,8 +530,6 @@ document.addEventListener("jpush.receiveMessage", function (event) {
|
||||
}, false)
|
||||
```
|
||||
|
||||
> ps:点击通知后传递的 json object 保存在 window.JPush.receiveMessage,直接访问即可,字段示例,根据实际推送情况,可能略有差别,请注意。
|
||||
|
||||
- Android:
|
||||
|
||||
```json
|
||||
@@ -545,4 +578,4 @@ window.JPush.getUserNotificationSettings(function(result) {
|
||||
} else if(result > 0) {
|
||||
// 系统设置中打开了应用推送。
|
||||
})
|
||||
```
|
||||
```
|
||||
|
||||
@@ -143,7 +143,7 @@ window.JPush.getRegistrationID(function(data) {
|
||||
|
||||
#### event - jpush.openNotification
|
||||
|
||||
点击通知启动或唤醒应用程序时会出发该事件
|
||||
点击通知启动或唤醒应用程序时会触发该事件
|
||||
|
||||
#### 代码示例
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "jpush-phonegap-plugin",
|
||||
"version": "3.2.8",
|
||||
"version": "3.2.12",
|
||||
"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.12">
|
||||
|
||||
<name>JPush</name>
|
||||
<description>JPush for cordova plugin</description>
|
||||
|
||||
@@ -28,25 +28,23 @@
|
||||
return [self init_plus];
|
||||
}
|
||||
|
||||
-(void)fireOpenNotification:(NSTimer*)timer{
|
||||
if (SharedJPushPlugin) {
|
||||
[JPushPlugin fireDocumentEvent:JPushDocumentEvent_OpenNotification jsString:[timer.userInfo toJsonString]];
|
||||
[timer invalidate];
|
||||
}
|
||||
}
|
||||
|
||||
NSDictionary *_launchOptions;
|
||||
-(void)applicationDidLaunch:(NSNotification *)notification{
|
||||
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(jpushSDKDidLoginNotification) name:kJPFNetworkDidLoginNotification object:nil];
|
||||
if (!_jpushEventCache) {
|
||||
_jpushEventCache = @{}.mutableCopy;
|
||||
}
|
||||
|
||||
[JPUSHService registrationIDCompletionHandler:^(int resCode, NSString *registrationID) {
|
||||
NSDictionary *event = @{@"registrationId": registrationID?:@""};
|
||||
[JPushPlugin fireDocumentEvent:JPushDocumentEvent_receiveRegistrationId jsString:[event toJsonString]];
|
||||
}];
|
||||
|
||||
if (notification) {
|
||||
if (notification.userInfo) {
|
||||
|
||||
if ([notification.userInfo valueForKey:UIApplicationLaunchOptionsRemoteNotificationKey]) {
|
||||
[NSTimer scheduledTimerWithTimeInterval:0.01 target:self selector:@selector(fireOpenNotification:)
|
||||
userInfo:[notification.userInfo
|
||||
valueForKey:UIApplicationLaunchOptionsRemoteNotificationKey] repeats:YES];
|
||||
[JPushPlugin fireDocumentEvent:JPushDocumentEvent_OpenNotification jsString:[notification.userInfo toJsonString]];
|
||||
}
|
||||
|
||||
if ([notification.userInfo valueForKey:UIApplicationLaunchOptionsLocalNotificationKey]) {
|
||||
@@ -56,7 +54,7 @@ NSDictionary *_launchOptions;
|
||||
@"badge": @(localNotification.applicationIconBadgeNumber),
|
||||
@"extras":localNotification.userInfo,
|
||||
};
|
||||
[NSTimer scheduledTimerWithTimeInterval:0.01 target:self selector:@selector(fireOpenNotification:) userInfo:localNotificationEvent repeats:YES];
|
||||
[JPushPlugin fireDocumentEvent:JPushDocumentEvent_OpenNotification jsString:[localNotificationEvent toJsonString]];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -155,7 +153,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 {
|
||||
|
||||
@@ -8,6 +8,8 @@
|
||||
|
||||
#import <Cordova/CDV.h>
|
||||
|
||||
static NSMutableDictionary *_jpushEventCache;
|
||||
|
||||
@interface JPushPlugin : CDVPlugin{
|
||||
|
||||
}
|
||||
@@ -87,7 +89,7 @@
|
||||
|
||||
@end
|
||||
|
||||
JPushPlugin *SharedJPushPlugin;
|
||||
static JPushPlugin *SharedJPushPlugin;
|
||||
|
||||
@interface NSDictionary (JPush)
|
||||
-(NSString*)toJsonString;
|
||||
|
||||
@@ -79,12 +79,39 @@
|
||||
selector:@selector(networkDidReceiveMessage:)
|
||||
name:kJPFNetworkDidReceiveMessageNotification
|
||||
object:nil];
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self
|
||||
selector:@selector(receiveLocalNotification:)
|
||||
name:JPushDocumentEvent_ReceiveLocalNotification
|
||||
object:nil];
|
||||
[self dispatchJPushCacheEvent];
|
||||
}
|
||||
|
||||
- (void)dispatchJPushCacheEvent {
|
||||
for (NSString* key in _jpushEventCache) {
|
||||
NSArray *evenList = _jpushEventCache[key];
|
||||
for (NSString *event in evenList) {
|
||||
[JPushPlugin fireDocumentEvent:key jsString:event];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+(void)fireDocumentEvent:(NSString*)eventName jsString:(NSString*)jsString{
|
||||
if (SharedJPushPlugin) {
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[SharedJPushPlugin.commandDelegate evalJs:[NSString stringWithFormat:@"cordova.fireDocumentEvent('jpush.%@',%@)", eventName, jsString]];
|
||||
[SharedJPushPlugin.commandDelegate evalJs:[NSString stringWithFormat:@"cordova.fireDocumentEvent('jpush.%@',%@)", eventName, jsString]];
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
if (!_jpushEventCache) {
|
||||
_jpushEventCache = @{}.mutableCopy;
|
||||
}
|
||||
|
||||
if (!_jpushEventCache[eventName]) {
|
||||
_jpushEventCache[eventName] = @[].mutableCopy;
|
||||
}
|
||||
|
||||
[_jpushEventCache[eventName] addObject: jsString];
|
||||
}
|
||||
|
||||
-(void)setTags:(CDVInvokedUrlCommand*)command {
|
||||
@@ -347,14 +374,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 +566,10 @@
|
||||
}
|
||||
}
|
||||
|
||||
-(void)receiveLocalNotification:(NSNotification *)notification {
|
||||
if (notification && notification.object) {
|
||||
[JPushPlugin fireDocumentEvent:JPushDocumentEvent_ReceiveLocalNotification
|
||||
jsString:[notification.object toJsonString]];
|
||||
}
|
||||
}
|
||||
@end
|
||||
|
||||
Reference in New Issue
Block a user