mirror of
https://github.com/jpush/jpush-phonegap-plugin.git
synced 2026-04-01 00:00:20 +08:00
Compare commits
11 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
07c9b2b945 | ||
|
|
8811dfc002 | ||
|
|
0ee5f8b1a0 | ||
|
|
259ec0a03a | ||
|
|
6283cb26f6 | ||
|
|
1c3228848b | ||
|
|
585e2a5084 | ||
|
|
c726477cfb | ||
|
|
3f00143a5a | ||
|
|
f5ea2b5b10 | ||
|
|
266d0cb28f |
@@ -1,7 +1,7 @@
|
|||||||
# JPush PhoneGap / Cordova Plugin
|
# JPush PhoneGap / Cordova Plugin
|
||||||
|
|
||||||
[](https://travis-ci.org/jpush/jpush-phonegap-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)
|
[](https://github.com/jpush/jpush-phonegap-plugin)
|
||||||
[](http://weibo.com/jpush?refer_flag=1001030101_&is_all=1)
|
[](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)
|
## 获取集成日志(同时适用于 iOS)
|
||||||
|
|
||||||
### API - setDebugMode
|
### API - setDebugMode
|
||||||
@@ -103,7 +90,7 @@ window.JPush.setPushTime(days, startHour, endHour)
|
|||||||
#### 参数说明
|
#### 参数说明
|
||||||
|
|
||||||
- days: 数组,0 表示星期天,1 表示星期一,以此类推(7天制,数组中值的范围为 0 到 6 )。
|
- days: 数组,0 表示星期天,1 表示星期一,以此类推(7天制,数组中值的范围为 0 到 6 )。
|
||||||
数组的值为 null, 表示任何时间都可以收到消息和通知,数组的 size 为 0,则表示任何时间都收不到消息和通知。
|
数组的值为 null, 表示任何时间都可以收到消息和通知,数组的 size 为 0,则表示任何时间都收不到消息和通知。
|
||||||
- startHour: 整形,允许推送的开始时间 (24 小时制:startHour 的范围为 0 到 23)。
|
- startHour: 整形,允许推送的开始时间 (24 小时制:startHour 的范围为 0 到 23)。
|
||||||
- endHour: 整形,允许推送的结束时间 (24 小时制:endHour 的范围为 0 到 23)。
|
- endHour: 整形,允许推送的结束时间 (24 小时制:endHour 的范围为 0 到 23)。
|
||||||
|
|
||||||
|
|||||||
@@ -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 提供的推送服务。
|
||||||
@@ -545,4 +562,4 @@ window.JPush.getUserNotificationSettings(function(result) {
|
|||||||
} else if(result > 0) {
|
} else if(result > 0) {
|
||||||
// 系统设置中打开了应用推送。
|
// 系统设置中打开了应用推送。
|
||||||
})
|
})
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -437,9 +437,7 @@ window.JPush.clearAllLocalNotifications()
|
|||||||
|
|
||||||
监听 [jpush.receiveNotification](#前台收到推送)、[jpush.openNotification](点击推送通知),获取推送内容后,通过获取到的 `__JPUSHNotificationKey` 字段([本地通知](#本地通知) 设置的 `notificationID`)来判断是本地通知,并处理。
|
监听 [jpush.receiveNotification](#前台收到推送)、[jpush.openNotification](点击推送通知),获取推送内容后,通过获取到的 `__JPUSHNotificationKey` 字段([本地通知](#本地通知) 设置的 `notificationID`)来判断是本地通知,并处理。
|
||||||
|
|
||||||
### 点击本地通知横幅启动 App
|
|
||||||
|
|
||||||
监听 `jpush.startLocalNotification` 事件。
|
|
||||||
|
|
||||||
## 页面的统计
|
## 页面的统计
|
||||||
|
|
||||||
@@ -718,18 +716,10 @@ window.JPush.getUserNotificationSettings(callback)
|
|||||||
|
|
||||||
[iOS 7 以后后台收到远程通知](#后台收到推送)
|
[iOS 7 以后后台收到远程通知](#后台收到推送)
|
||||||
|
|
||||||
### jpush.setTagsWithAlias
|
|
||||||
|
|
||||||
[设置标签别名回调](#返回值说明)
|
|
||||||
|
|
||||||
### jpush.receiveMessage
|
### jpush.receiveMessage
|
||||||
|
|
||||||
[获取自定义消息内容](#获取自定义消息内容)
|
[获取自定义消息内容](#获取自定义消息内容)
|
||||||
|
|
||||||
### jpush.startLocalNotification
|
|
||||||
|
|
||||||
[点击本地通知横幅启动 App](#点击本地通知横幅启动-app)
|
|
||||||
|
|
||||||
### jpush.receiveLocalNotification
|
### jpush.receiveLocalNotification
|
||||||
|
|
||||||
[iOS 10 before 收到本地通知](#ios-10-before-收到本地通知)
|
[iOS 10 before 收到本地通知](#ios-10-before-收到本地通知)
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "jpush-phonegap-plugin",
|
"name": "jpush-phonegap-plugin",
|
||||||
"version": "3.2.5",
|
"version": "3.2.8",
|
||||||
"description": "JPush for cordova plugin",
|
"description": "JPush for cordova plugin",
|
||||||
"cordova": {
|
"cordova": {
|
||||||
"id": "jpush-phonegap-plugin",
|
"id": "jpush-phonegap-plugin",
|
||||||
|
|||||||
11
plugin.xml
11
plugin.xml
@@ -2,7 +2,7 @@
|
|||||||
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
|
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
id="jpush-phonegap-plugin"
|
id="jpush-phonegap-plugin"
|
||||||
version="3.2.5">
|
version="3.2.8">
|
||||||
|
|
||||||
<name>JPush</name>
|
<name>JPush</name>
|
||||||
<description>JPush for cordova plugin</description>
|
<description>JPush for cordova plugin</description>
|
||||||
@@ -38,7 +38,7 @@
|
|||||||
<source-file src="src/ios/Plugins/AppDelegate+JPush.m" />
|
<source-file src="src/ios/Plugins/AppDelegate+JPush.m" />
|
||||||
|
|
||||||
<header-file src="src/ios/lib/JPUSHService.h" />
|
<header-file src="src/ios/lib/JPUSHService.h" />
|
||||||
<source-file src="src/ios/lib/jpush-ios-3.0.6.a" framework="true" />
|
<source-file src="src/ios/lib/jpush-ios-3.0.7.a" framework="true" />
|
||||||
<resource-file src="src/ios/JPushConfig.plist" />
|
<resource-file src="src/ios/JPushConfig.plist" />
|
||||||
|
|
||||||
<framework src="CFNetwork.framework" weak="true" />
|
<framework src="CFNetwork.framework" weak="true" />
|
||||||
@@ -195,6 +195,13 @@
|
|||||||
android:name="cn.jpush.android.service.DataProvider"
|
android:name="cn.jpush.android.service.DataProvider"
|
||||||
android:exported="true" />
|
android:exported="true" />
|
||||||
|
|
||||||
|
<receiver android:name="cn.jiguang.cordova.push.JPushEventReceiver">
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="cn.jpush.android.intent.RECEIVE_MESSAGE" />
|
||||||
|
<category android:name="$PACKAGE_NAME"></category>
|
||||||
|
</intent-filter>
|
||||||
|
</receiver>
|
||||||
|
|
||||||
<!-- Required. Enable it you can get statistics data with channel -->
|
<!-- Required. Enable it you can get statistics data with channel -->
|
||||||
<meta-data android:name="JPUSH_CHANNEL" android:value="developer-default" />
|
<meta-data android:name="JPUSH_CHANNEL" android:value="developer-default" />
|
||||||
<meta-data android:name="JPUSH_APPKEY" android:value="$APP_KEY" />
|
<meta-data android:name="JPUSH_APPKEY" android:value="$APP_KEY" />
|
||||||
|
|||||||
@@ -527,24 +527,6 @@ public class JPushPlugin extends CordovaPlugin {
|
|||||||
eventCallbackMap.put(sequence, callbackContext);
|
eventCallbackMap.put(sequence, callbackContext);
|
||||||
}
|
}
|
||||||
|
|
||||||
void setTagsWithAlias(JSONArray data, CallbackContext callbackContext) {
|
|
||||||
HashSet<String> tags = new HashSet<String>();
|
|
||||||
String alias;
|
|
||||||
try {
|
|
||||||
alias = data.getString(0);
|
|
||||||
JSONArray tagsArray = data.getJSONArray(1);
|
|
||||||
for (int i = 0; i < tagsArray.length(); i++) {
|
|
||||||
tags.add(tagsArray.getString(i));
|
|
||||||
}
|
|
||||||
JPushInterface.setAliasAndTags(mContext,
|
|
||||||
alias, tags, mTagWithAliasCallback);
|
|
||||||
callbackContext.success();
|
|
||||||
} catch (JSONException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
callbackContext.error("Error reading tagAlias JSON");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void getConnectionState(JSONArray data, CallbackContext callback) {
|
void getConnectionState(JSONArray data, CallbackContext callback) {
|
||||||
boolean isConnected = JPushInterface.getConnectionState(cordovaActivity.getApplicationContext());
|
boolean isConnected = JPushInterface.getConnectionState(cordovaActivity.getApplicationContext());
|
||||||
callback.success(String.valueOf(isConnected));
|
callback.success(String.valueOf(isConnected));
|
||||||
@@ -553,8 +535,7 @@ public class JPushPlugin extends CordovaPlugin {
|
|||||||
/**
|
/**
|
||||||
* 自定义通知行为,声音、震动、呼吸灯等。
|
* 自定义通知行为,声音、震动、呼吸灯等。
|
||||||
*/
|
*/
|
||||||
void setBasicPushNotificationBuilder(JSONArray data,
|
void setBasicPushNotificationBuilder(JSONArray data, CallbackContext callbackContext) {
|
||||||
CallbackContext callbackContext) {
|
|
||||||
BasicPushNotificationBuilder builder = new BasicPushNotificationBuilder(
|
BasicPushNotificationBuilder builder = new BasicPushNotificationBuilder(
|
||||||
this.cordova.getActivity());
|
this.cordova.getActivity());
|
||||||
builder.developerArg0 = "Basic builder 1";
|
builder.developerArg0 = "Basic builder 1";
|
||||||
|
|||||||
@@ -1,156 +1,175 @@
|
|||||||
//
|
//
|
||||||
// AppDelegate+JPush.m
|
// AppDelegate+JPush.m
|
||||||
// delegateExtention
|
// delegateExtention
|
||||||
//
|
//
|
||||||
// Created by 张庆贺 on 15/8/3.
|
// Created by 张庆贺 on 15/8/3.
|
||||||
// Copyright (c) 2015年 JPush. All rights reserved.
|
// Copyright (c) 2015年 JPush. All rights reserved.
|
||||||
//
|
//
|
||||||
|
|
||||||
#import "AppDelegate+JPush.h"
|
#import "AppDelegate+JPush.h"
|
||||||
#import "JPushPlugin.h"
|
#import "JPushPlugin.h"
|
||||||
#import <objc/runtime.h>
|
#import <objc/runtime.h>
|
||||||
#import <AdSupport/AdSupport.h>
|
#import <AdSupport/AdSupport.h>
|
||||||
#import <UserNotifications/UserNotifications.h>
|
#import <UserNotifications/UserNotifications.h>
|
||||||
#import "JPushDefine.h"
|
#import "JPushDefine.h"
|
||||||
|
|
||||||
@implementation AppDelegate (JPush)
|
@implementation AppDelegate (JPush)
|
||||||
|
|
||||||
+(void)load{
|
+(void)load{
|
||||||
Method origin1;
|
Method origin1;
|
||||||
Method swizzle1;
|
Method swizzle1;
|
||||||
origin1 = class_getInstanceMethod([self class],@selector(init));
|
origin1 = class_getInstanceMethod([self class],@selector(init));
|
||||||
swizzle1 = class_getInstanceMethod([self class], @selector(init_plus));
|
swizzle1 = class_getInstanceMethod([self class], @selector(init_plus));
|
||||||
method_exchangeImplementations(origin1, swizzle1);
|
method_exchangeImplementations(origin1, swizzle1);
|
||||||
}
|
}
|
||||||
|
|
||||||
-(instancetype)init_plus{
|
-(instancetype)init_plus{
|
||||||
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationDidLaunch:) name:UIApplicationDidFinishLaunchingNotification object:nil];
|
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationDidLaunch:) name:UIApplicationDidFinishLaunchingNotification object:nil];
|
||||||
return [self init_plus];
|
return [self init_plus];
|
||||||
}
|
}
|
||||||
|
|
||||||
-(void)fireOpenNotification:(NSTimer*)timer{
|
-(void)fireOpenNotification:(NSTimer*)timer{
|
||||||
if (SharedJPushPlugin) {
|
if (SharedJPushPlugin) {
|
||||||
[JPushPlugin fireDocumentEvent:JPushDocumentEvent_OpenNotification jsString:[timer.userInfo toJsonString]];
|
[JPushPlugin fireDocumentEvent:JPushDocumentEvent_OpenNotification jsString:[timer.userInfo toJsonString]];
|
||||||
[timer invalidate];
|
[timer invalidate];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
NSDictionary *_launchOptions;
|
NSDictionary *_launchOptions;
|
||||||
-(void)applicationDidLaunch:(NSNotification *)notification{
|
-(void)applicationDidLaunch:(NSNotification *)notification{
|
||||||
|
|
||||||
|
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(jpushSDKDidLoginNotification) name:kJPFNetworkDidLoginNotification object:nil];
|
||||||
if (notification) {
|
|
||||||
if (notification.userInfo) {
|
if (notification) {
|
||||||
NSDictionary *userInfo1 = [notification.userInfo valueForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
|
if (notification.userInfo) {
|
||||||
if (userInfo1.count > 0) {
|
|
||||||
[NSTimer scheduledTimerWithTimeInterval:0.01 target:self selector:@selector(fireOpenNotification:) userInfo:userInfo1 repeats:YES];
|
if ([notification.userInfo valueForKey:UIApplicationLaunchOptionsRemoteNotificationKey]) {
|
||||||
}
|
[NSTimer scheduledTimerWithTimeInterval:0.01 target:self selector:@selector(fireOpenNotification:)
|
||||||
|
userInfo:[notification.userInfo
|
||||||
NSDictionary *userInfo2 = [notification.userInfo valueForKey:UIApplicationLaunchOptionsLocalNotificationKey];
|
valueForKey:UIApplicationLaunchOptionsRemoteNotificationKey] repeats:YES];
|
||||||
if (userInfo2.count > 0) {
|
}
|
||||||
[NSTimer scheduledTimerWithTimeInterval:0.01 target:self selector:@selector(fireOpenNotification:) userInfo:userInfo2 repeats:YES];
|
|
||||||
}
|
if ([notification.userInfo valueForKey:UIApplicationLaunchOptionsLocalNotificationKey]) {
|
||||||
}
|
UILocalNotification *localNotification = [notification.userInfo valueForKey:UIApplicationLaunchOptionsLocalNotificationKey];
|
||||||
[JPUSHService setDebugMode];
|
|
||||||
|
NSDictionary* localNotificationEvent = @{@"content":localNotification.alertBody,
|
||||||
NSString *plistPath = [[NSBundle mainBundle] pathForResource:JPushConfig_FileName ofType:@"plist"];
|
@"badge": @(localNotification.applicationIconBadgeNumber),
|
||||||
NSMutableDictionary *plistData = [[NSMutableDictionary alloc] initWithContentsOfFile:plistPath];
|
@"extras":localNotification.userInfo,
|
||||||
NSNumber *delay = [plistData valueForKey:JPushConfig_Delay];
|
};
|
||||||
|
[NSTimer scheduledTimerWithTimeInterval:0.01 target:self selector:@selector(fireOpenNotification:) userInfo:localNotificationEvent repeats:YES];
|
||||||
_launchOptions = notification.userInfo;
|
}
|
||||||
|
}
|
||||||
if (![delay boolValue]) {
|
|
||||||
[self startJPushSDK];
|
[JPUSHService setDebugMode];
|
||||||
}
|
|
||||||
}
|
NSString *plistPath = [[NSBundle mainBundle] pathForResource:JPushConfig_FileName ofType:@"plist"];
|
||||||
}
|
NSMutableDictionary *plistData = [[NSMutableDictionary alloc] initWithContentsOfFile:plistPath];
|
||||||
|
NSNumber *delay = [plistData valueForKey:JPushConfig_Delay];
|
||||||
-(void)startJPushSDK{
|
|
||||||
[self registerForRemoteNotification];
|
_launchOptions = notification.userInfo;
|
||||||
[JPushPlugin setupJPushSDK:_launchOptions];
|
|
||||||
}
|
if (![delay boolValue]) {
|
||||||
|
[self startJPushSDK];
|
||||||
-(void)registerForRemoteNotification{
|
}
|
||||||
if ([[UIDevice currentDevice].systemVersion floatValue] >= 10.0) {
|
}
|
||||||
#ifdef NSFoundationVersionNumber_iOS_9_x_Max
|
}
|
||||||
JPUSHRegisterEntity * entity = [[JPUSHRegisterEntity alloc] init];
|
|
||||||
entity.types = UNAuthorizationOptionAlert|UNAuthorizationOptionBadge|UNAuthorizationOptionSound;
|
-(void)startJPushSDK{
|
||||||
[JPUSHService registerForRemoteNotificationConfig:entity delegate:self];
|
[self registerForRemoteNotification];
|
||||||
#endif
|
[JPushPlugin setupJPushSDK:_launchOptions];
|
||||||
}else if ([[UIDevice currentDevice].systemVersion floatValue] >= 8.0) {
|
}
|
||||||
//可以添加自定义categories
|
|
||||||
[JPUSHService registerForRemoteNotificationTypes:(UIUserNotificationTypeBadge |
|
- (void)jpushSDKDidLoginNotification {
|
||||||
UIUserNotificationTypeSound |
|
NSDictionary *event = @{@"registrationId": JPUSHService.registrationID};
|
||||||
UIUserNotificationTypeAlert)
|
[JPushPlugin fireDocumentEvent:JPushDocumentEvent_receiveRegistrationId jsString:[event toJsonString]];
|
||||||
categories:nil];
|
}
|
||||||
} else if([[UIDevice currentDevice].systemVersion floatValue] < 8.0){
|
|
||||||
//categories 必须为nil
|
-(void)registerForRemoteNotification{
|
||||||
[JPUSHService registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge |
|
if ([[UIDevice currentDevice].systemVersion floatValue] >= 10.0) {
|
||||||
UIRemoteNotificationTypeSound |
|
#ifdef NSFoundationVersionNumber_iOS_9_x_Max
|
||||||
UIRemoteNotificationTypeAlert)
|
JPUSHRegisterEntity * entity = [[JPUSHRegisterEntity alloc] init];
|
||||||
categories:nil];
|
entity.types = UNAuthorizationOptionAlert|UNAuthorizationOptionBadge|UNAuthorizationOptionSound;
|
||||||
}
|
[JPUSHService registerForRemoteNotificationConfig:entity delegate:self];
|
||||||
}
|
#endif
|
||||||
|
}else if ([[UIDevice currentDevice].systemVersion floatValue] >= 8.0) {
|
||||||
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
|
//可以添加自定义categories
|
||||||
[JPUSHService registerDeviceToken:deviceToken];
|
[JPUSHService registerForRemoteNotificationTypes:(UIUserNotificationTypeBadge |
|
||||||
}
|
UIUserNotificationTypeSound |
|
||||||
|
UIUserNotificationTypeAlert)
|
||||||
-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo{
|
categories:nil];
|
||||||
[JPUSHService handleRemoteNotification:userInfo];
|
} else if([[UIDevice currentDevice].systemVersion floatValue] < 8.0){
|
||||||
|
//categories 必须为nil
|
||||||
[JPushPlugin fireDocumentEvent:JPushDocumentEvent_ReceiveNotification jsString:[userInfo toJsonString]];
|
[JPUSHService registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge |
|
||||||
}
|
UIRemoteNotificationTypeSound |
|
||||||
|
UIRemoteNotificationTypeAlert)
|
||||||
-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler{
|
categories:nil];
|
||||||
[JPUSHService handleRemoteNotification:userInfo];
|
}
|
||||||
NSString *eventName;
|
}
|
||||||
switch ([UIApplication sharedApplication].applicationState) {
|
|
||||||
case UIApplicationStateInactive:
|
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
|
||||||
eventName = JPushDocumentEvent_OpenNotification;
|
[JPUSHService registerDeviceToken:deviceToken];
|
||||||
break;
|
}
|
||||||
case UIApplicationStateActive:
|
|
||||||
eventName = JPushDocumentEvent_ReceiveNotification;
|
-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo{
|
||||||
break;
|
[JPUSHService handleRemoteNotification:userInfo];
|
||||||
case UIApplicationStateBackground:
|
|
||||||
eventName = JPushDocumentEvent_BackgroundNotification;
|
[JPushPlugin fireDocumentEvent:JPushDocumentEvent_ReceiveNotification jsString:[userInfo toJsonString]];
|
||||||
break;
|
}
|
||||||
default:
|
|
||||||
break;
|
-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler{
|
||||||
}
|
[JPUSHService handleRemoteNotification:userInfo];
|
||||||
[JPushPlugin fireDocumentEvent:eventName jsString:[userInfo toJsonString]];
|
NSString *eventName;
|
||||||
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(30 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
|
switch ([UIApplication sharedApplication].applicationState) {
|
||||||
completionHandler(UIBackgroundFetchResultNewData);
|
case UIApplicationStateInactive:
|
||||||
});
|
eventName = JPushDocumentEvent_OpenNotification;
|
||||||
}
|
break;
|
||||||
|
case UIApplicationStateActive:
|
||||||
-(void)jpushNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(NSInteger))completionHandler{
|
eventName = JPushDocumentEvent_ReceiveNotification;
|
||||||
NSMutableDictionary *userInfo = [NSMutableDictionary dictionaryWithDictionary:notification.request.content.userInfo];
|
break;
|
||||||
[JPushPlugin fireDocumentEvent:JPushDocumentEvent_ReceiveNotification jsString:[userInfo toJsonString]];
|
case UIApplicationStateBackground:
|
||||||
completionHandler(UNNotificationPresentationOptionBadge|UNNotificationPresentationOptionSound|UNNotificationPresentationOptionAlert);
|
eventName = JPushDocumentEvent_BackgroundNotification;
|
||||||
}
|
break;
|
||||||
|
default:
|
||||||
-(void)jpushNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)())completionHandler{
|
break;
|
||||||
NSMutableDictionary *userInfo = [NSMutableDictionary dictionaryWithDictionary:response.notification.request.content.userInfo];
|
}
|
||||||
@try {
|
[JPushPlugin fireDocumentEvent:eventName jsString:[userInfo toJsonString]];
|
||||||
[userInfo setValue:[response valueForKey:@"userText"] forKey:@"userText"];
|
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(30 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
|
||||||
} @catch (NSException *exception) { }
|
completionHandler(UIBackgroundFetchResultNewData);
|
||||||
[userInfo setValue:response.actionIdentifier forKey:@"actionIdentifier"];
|
});
|
||||||
[JPushPlugin fireDocumentEvent:JPushDocumentEvent_OpenNotification jsString:[userInfo toJsonString]];
|
}
|
||||||
completionHandler();
|
|
||||||
}
|
-(void)jpushNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(NSInteger))completionHandler{
|
||||||
|
NSMutableDictionary *userInfo = [NSMutableDictionary dictionaryWithDictionary:notification.request.content.userInfo];
|
||||||
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification {
|
[JPushPlugin fireDocumentEvent:JPushDocumentEvent_ReceiveNotification jsString:[userInfo toJsonString]];
|
||||||
[[NSNotificationCenter defaultCenter] postNotificationName:JPushDocumentEvent_ReceiveLocalNotification object:notification.userInfo];
|
completionHandler(UNNotificationPresentationOptionBadge|UNNotificationPresentationOptionSound|UNNotificationPresentationOptionAlert);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)applicationWillEnterForeground:(UIApplication *)application {
|
-(void)jpushNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)())completionHandler{
|
||||||
// [application setApplicationIconBadgeNumber:0];
|
NSMutableDictionary *userInfo = [NSMutableDictionary dictionaryWithDictionary:response.notification.request.content.userInfo];
|
||||||
// [application cancelAllLocalNotifications];
|
@try {
|
||||||
}
|
[userInfo setValue:[response valueForKey:@"userText"] forKey:@"userText"];
|
||||||
|
} @catch (NSException *exception) { }
|
||||||
- (void)applicationDidEnterBackground:(UIApplication *)application {
|
[userInfo setValue:response.actionIdentifier forKey:@"actionIdentifier"];
|
||||||
// [[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];
|
[JPushPlugin fireDocumentEvent:JPushDocumentEvent_OpenNotification jsString:[userInfo toJsonString]];
|
||||||
}
|
completionHandler();
|
||||||
|
}
|
||||||
@end
|
|
||||||
|
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification {
|
||||||
|
NSDictionary* localNotificationEvent = @{@"content":notification.alertBody,
|
||||||
|
@"badge": @(notification.applicationIconBadgeNumber),
|
||||||
|
@"extras":notification.userInfo,
|
||||||
|
};
|
||||||
|
|
||||||
|
[[NSNotificationCenter defaultCenter] postNotificationName:JPushDocumentEvent_ReceiveLocalNotification object:localNotificationEvent];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)applicationWillEnterForeground:(UIApplication *)application {
|
||||||
|
// [application setApplicationIconBadgeNumber:0];
|
||||||
|
// [application cancelAllLocalNotifications];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)applicationDidEnterBackground:(UIApplication *)application {
|
||||||
|
// [[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];
|
||||||
|
}
|
||||||
|
|
||||||
|
@end
|
||||||
|
|||||||
@@ -27,7 +27,6 @@ static NSString *const JPushDocumentEvent_OpenNotification = @"openNoti
|
|||||||
static NSString *const JPushDocumentEvent_BackgroundNotification = @"backgroundNotification";
|
static NSString *const JPushDocumentEvent_BackgroundNotification = @"backgroundNotification";
|
||||||
static NSString *const JPushDocumentEvent_SetTagsWithAlias = @"setTagsWithAlias";
|
static NSString *const JPushDocumentEvent_SetTagsWithAlias = @"setTagsWithAlias";
|
||||||
static NSString *const JPushDocumentEvent_ReceiveMessage = @"receiveMessage";
|
static NSString *const JPushDocumentEvent_ReceiveMessage = @"receiveMessage";
|
||||||
static NSString *const JPushDocumentEvent_StartLocalNotification = @"startLocalNotification";
|
|
||||||
static NSString *const JPushDocumentEvent_ReceiveLocalNotification = @"receiveLocalNotification";
|
static NSString *const JPushDocumentEvent_ReceiveLocalNotification = @"receiveLocalNotification";
|
||||||
|
|
||||||
|
static NSString *const JPushDocumentEvent_receiveRegistrationId = @"receiveRegistrationId";
|
||||||
|
|||||||
@@ -17,8 +17,6 @@
|
|||||||
|
|
||||||
//以下为js中可调用接口
|
//以下为js中可调用接口
|
||||||
//设置标签、别名
|
//设置标签、别名
|
||||||
-(void)setTagsWithAlias:(CDVInvokedUrlCommand*)command;
|
|
||||||
|
|
||||||
-(void)setTags:(CDVInvokedUrlCommand*)command;
|
-(void)setTags:(CDVInvokedUrlCommand*)command;
|
||||||
-(void)addTags:(CDVInvokedUrlCommand*)command;
|
-(void)addTags:(CDVInvokedUrlCommand*)command;
|
||||||
-(void)deleteTags:(CDVInvokedUrlCommand*)command;
|
-(void)deleteTags:(CDVInvokedUrlCommand*)command;
|
||||||
@@ -76,7 +74,6 @@
|
|||||||
/*
|
/*
|
||||||
* 以下为js中可监听到的事件
|
* 以下为js中可监听到的事件
|
||||||
* jpush.openNotification 点击推送消息启动或唤醒app
|
* jpush.openNotification 点击推送消息启动或唤醒app
|
||||||
* jpush.setTagsWithAlias 设置标签、别名完成
|
|
||||||
* jpush.receiveMessage 收到自定义消息
|
* jpush.receiveMessage 收到自定义消息
|
||||||
* jpush.receiveNotification 前台收到推送
|
* jpush.receiveNotification 前台收到推送
|
||||||
* jpush.backgroundNotification 后台收到推送
|
* jpush.backgroundNotification 后台收到推送
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -9,7 +9,7 @@
|
|||||||
* Copyright (c) 2011 ~ 2017 Shenzhen HXHG. All rights reserved.
|
* Copyright (c) 2011 ~ 2017 Shenzhen HXHG. All rights reserved.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define JPUSH_VERSION_NUMBER 3.0.6
|
#define JPUSH_VERSION_NUMBER 3.0.7
|
||||||
|
|
||||||
#import <Foundation/Foundation.h>
|
#import <Foundation/Foundation.h>
|
||||||
|
|
||||||
|
|||||||
Binary file not shown.
@@ -70,20 +70,6 @@ JPushPlugin.prototype.clearLocalNotifications = function () {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
JPushPlugin.prototype.setTagsWithAlias = function (tags, alias, successCallback, errorCallback) {
|
|
||||||
if (tags == null) {
|
|
||||||
this.setAlias(alias)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if (alias == null) {
|
|
||||||
this.setTags(tags)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
var arrayTagWithAlias = [tags]
|
|
||||||
arrayTagWithAlias.unshift(alias)
|
|
||||||
this.callNative('setTagsWithAlias', arrayTagWithAlias, successCallback, errorCallback)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 设置标签。
|
* 设置标签。
|
||||||
* 注意:该接口是覆盖逻辑,而不是增量逻辑。即新的调用会覆盖之前的设置。
|
* 注意:该接口是覆盖逻辑,而不是增量逻辑。即新的调用会覆盖之前的设置。
|
||||||
|
|||||||
Reference in New Issue
Block a user