Compare commits

..

14 Commits

Author SHA1 Message Date
Hevin edf29bbc8d Merge branch 'dev' 2017-09-28 10:25:03 +08:00
Hevin ae54960da4 Merge branch 'dev' 2017-09-26 18:28:44 +08:00
Hevin ea6011635f Merge branch 'dev' 2017-09-25 12:32:36 +08:00
Hevin 0829104534 Merge branch 'dev' 2017-09-23 09:11:34 +08:00
Hevin 592d5a5fb9 Merge branch 'dev' 2017-09-22 21:16:11 +08:00
Hevin 4753174bda Merge branch 'dev' 2017-09-22 20:24:21 +08:00
Hevin 3f077e32fd Merge branch 'dev' 2017-09-19 14:33:24 +08:00
Hevin 5c569d00da Merge branch 'dev' 2017-09-08 14:32:18 +08:00
Hevin c5f7963425 Merge branch 'dev' 2017-07-21 14:15:57 +08:00
Hevin a4eaf51455 Merge branch 'dev' 2017-07-21 14:00:30 +08:00
Hevin 04fae7d538 Merge branch 'dev' 2017-07-12 10:16:49 +08:00
Hevin 8e087e102a Merge branch 'dev' 2017-07-07 11:26:20 +08:00
Hevin 35c09c0c92 Merge branch 'dev' 2017-07-04 17:51:51 +08:00
Hevin f0a87962e7 Merge branch 'dev' 2017-06-30 15:44:35 +08:00
14 changed files with 870 additions and 912 deletions
+2 -2
View File
@@ -1,7 +1,7 @@
# JPush PhoneGap / Cordova Plugin # 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) [![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.12-blue.svg)](https://github.com/jpush/jpush-phonegap-plugin/releases) [![release](https://img.shields.io/badge/release-3.2.6-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) [![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) [![weibo](https://img.shields.io/badge/weibo-JPush-blue.svg)](http://weibo.com/jpush?refer_flag=1001030101_&is_all=1)
@@ -28,7 +28,7 @@
- 或下载到本地安装: - 或下载到本地安装:
```shell ```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 开关。 > 在使用 Xcode 8 调试 iOS 项目时,需要先在项目配置界面的 Capabilities 中打开 Push Notifications 开关。
+16 -1
View File
@@ -1,5 +1,7 @@
# Android API 简介 # Android API 简介
- [注册成功事件](#注册成功事件)
- [获取集成日志(同时适用于 iOS](#获取集成日志同时适用于-ios)
- [清除通知](#清除通知) - [清除通知](#清除通知)
- [设置允许推送时间](#设置允许推送时间) - [设置允许推送时间](#设置允许推送时间)
- [设置通知静默时间](#设置通知静默时间) - [设置通知静默时间](#设置通知静默时间)
@@ -7,6 +9,19 @@
- [设置保留最近通知条数](#设置保留最近通知条数) - [设置保留最近通知条数](#设置保留最近通知条数)
- [本地通知](#本地通知) - [本地通知](#本地通知)
## 注册成功事件
### 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
@@ -88,7 +103,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)。
+19 -52
View File
@@ -1,52 +1,15 @@
# 通用 API 说明(同时适用于 Android 和 iOS 系统) # 通用 API 说明(同时适用于 Android 和 iOS 系统)
- [注册成功事件](#注册成功事件) - [停止与恢复推送服务](#停止与恢复推送服务)
- [jpush.receiveRegistrationId](#jpushreceiveregistrationid)
- [初始化、停止与恢复推送服务](#初始化停止与恢复推送服务)
- [init](#init)
- [stopPush](#stoppush)
- [resumePush](#resumepush)
- [isPushStopped](#ispushstopped)
- [开启 Debug 模式](#开启-debug-模式)
- [setDebugMode](#setdebugmode)
- [获取 RegistrationID](#获取-registrationid) - [获取 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 提供的推送服务。 调用此 API,用来开启 JPush SDK 提供的推送服务。
@@ -64,7 +27,7 @@ document.addEventListener('jpush.receiveRegistrationId', function (event) {
window.JPush.init() window.JPush.init()
``` ```
### stopPush ### API - stopPush
- Android: - Android:
- 开发者 App 可以通过调用停止推送服务 API 来停止极光推送服务,当又需要使用极光推送服务时,则必须要调用恢复推送服务 API。 - 开发者 App 可以通过调用停止推送服务 API 来停止极光推送服务,当又需要使用极光推送服务时,则必须要调用恢复推送服务 API。
@@ -83,7 +46,7 @@ window.JPush.init()
window.JPush.stopPush() window.JPush.stopPush()
``` ```
### resumePush ### API - resumePush
恢复推送服务。调用了此 API 后: 恢复推送服务。调用了此 API 后:
@@ -99,7 +62,7 @@ window.JPush.stopPush()
window.JPush.resumePush() window.JPush.resumePush()
``` ```
### isPushStopped ### API - isPushStopped
- Android 平台: - Android 平台:
- 用来检查 Push Service 是否已经被停止。 - 用来检查 Push Service 是否已经被停止。
@@ -130,7 +93,7 @@ window.JPush.isPushStopped(function (result) {
``` ```
## 开启 Debug 模式 ## 开启 Debug 模式
### setDebugMode ### API - setDebugMode
用于开启 Debug 模式,显示更多的日志信息。 用于开启 Debug 模式,显示更多的日志信息。
#### 代码示例 #### 代码示例
@@ -140,13 +103,11 @@ window.JPush.setDebugMode(true)
``` ```
#### 参数说明 #### 参数说明
- isOpen: true,开启 Debug 模式;false,关闭 Debug 模式,不显示错误信息之外的日志信息。
- true: 开启 Debug 模式;
- false: 关闭 Debug 模式,不显示错误信息之外的日志信息。
## 获取 RegistrationID ## 获取 RegistrationID
### getRegistrationID ### API - getRegistrationID
RegistrationID 定义: RegistrationID 定义:
@@ -400,7 +361,7 @@ window.JPush.checkTagBindState({ sequence: 1, tag: 'tag1' },
### event - jpush.openNotification ### event - jpush.openNotification
点击通知进入应用程序时触发 点击通知进入应用程序时会出发改事件
#### 代码示例 #### 代码示例
@@ -417,6 +378,8 @@ document.addEventListener("jpush.openNotification", function (event) {
}, false) }, false)
``` ```
> ps:点击通知后传递的 json object 保存在 window.JPush.openNotification,直接访问即可,字段示例,根据实际推送情况,可能略有差别,请注意。
- Android: - Android:
```json ```json
@@ -455,7 +418,7 @@ document.addEventListener("jpush.openNotification", function (event) {
### event - jpush.receiveNotification ### event - jpush.receiveNotification
收到通知时触发。 收到通知时触发该事件
#### 代码示例 #### 代码示例
@@ -473,6 +436,8 @@ document.addEventListener("jpush.receiveNotification", function (event) {
}, false) }, false)
``` ```
> ps:点击通知后传递的 json object 保存在 window.JPush.receiveNotification,直接访问即可,字段示例,根据实际推送情况,可能略有差别,请注意。
- Android: - Android:
```json ```json
@@ -511,7 +476,7 @@ document.addEventListener("jpush.receiveNotification", function (event) {
### event - jpush.receiveMessage ### event - jpush.receiveMessage
收到自定义消息时触发,推荐使用事件的方式传递。 收到自定义消息时触发这个事件,推荐使用事件的方式传递。
但同时保留了 `receiveMessageIniOSCallback` 的回调函数,兼容以前的代码。 但同时保留了 `receiveMessageIniOSCallback` 的回调函数,兼容以前的代码。
@@ -530,6 +495,8 @@ document.addEventListener("jpush.receiveMessage", function (event) {
}, false) }, false)
``` ```
> ps:点击通知后传递的 json object 保存在 window.JPush.receiveMessage,直接访问即可,字段示例,根据实际推送情况,可能略有差别,请注意。
- Android: - Android:
```json ```json
@@ -578,4 +545,4 @@ window.JPush.getUserNotificationSettings(function(result) {
} else if(result > 0) { } else if(result > 0) {
// 系统设置中打开了应用推送。 // 系统设置中打开了应用推送。
}) })
``` ```
+11 -1
View File
@@ -143,7 +143,7 @@ window.JPush.getRegistrationID(function(data) {
#### event - jpush.openNotification #### event - jpush.openNotification
点击通知启动或唤醒应用程序时会发该事件 点击通知启动或唤醒应用程序时会发该事件
#### 代码示例 #### 代码示例
@@ -437,7 +437,9 @@ window.JPush.clearAllLocalNotifications()
监听 [jpush.receiveNotification](#前台收到推送)、[jpush.openNotification](点击推送通知),获取推送内容后,通过获取到的 `__JPUSHNotificationKey` 字段([本地通知](#本地通知) 设置的 `notificationID`)来判断是本地通知,并处理。 监听 [jpush.receiveNotification](#前台收到推送)、[jpush.openNotification](点击推送通知),获取推送内容后,通过获取到的 `__JPUSHNotificationKey` 字段([本地通知](#本地通知) 设置的 `notificationID`)来判断是本地通知,并处理。
### 点击本地通知横幅启动 App
监听 `jpush.startLocalNotification` 事件。
## 页面的统计 ## 页面的统计
@@ -716,10 +718,18 @@ 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 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "jpush-phonegap-plugin", "name": "jpush-phonegap-plugin",
"version": "3.2.12", "version": "3.2.6",
"description": "JPush for cordova plugin", "description": "JPush for cordova plugin",
"cordova": { "cordova": {
"id": "jpush-phonegap-plugin", "id": "jpush-phonegap-plugin",
+2 -2
View File
@@ -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.12"> version="3.2.6">
<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.7.a" framework="true" /> <source-file src="src/ios/lib/jpush-ios-3.0.6.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" />
+20 -1
View File
@@ -527,6 +527,24 @@ 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));
@@ -535,7 +553,8 @@ public class JPushPlugin extends CordovaPlugin {
/** /**
* 自定义通知行为,声音、震动、呼吸灯等。 * 自定义通知行为,声音、震动、呼吸灯等。
*/ */
void setBasicPushNotificationBuilder(JSONArray data, CallbackContext callbackContext) { void setBasicPushNotificationBuilder(JSONArray data,
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";
+156 -173
View File
@@ -1,173 +1,156 @@
// //
// 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];
} }
NSDictionary *_launchOptions; -(void)fireOpenNotification:(NSTimer*)timer{
-(void)applicationDidLaunch:(NSNotification *)notification{ if (SharedJPushPlugin) {
[JPushPlugin fireDocumentEvent:JPushDocumentEvent_OpenNotification jsString:[timer.userInfo toJsonString]];
if (!_jpushEventCache) { [timer invalidate];
_jpushEventCache = @{}.mutableCopy; }
} }
[JPUSHService registrationIDCompletionHandler:^(int resCode, NSString *registrationID) { NSDictionary *_launchOptions;
NSDictionary *event = @{@"registrationId": registrationID?:@""}; -(void)applicationDidLaunch:(NSNotification *)notification{
[JPushPlugin fireDocumentEvent:JPushDocumentEvent_receiveRegistrationId jsString:[event toJsonString]];
}];
if (notification) {
if (notification) { if (notification.userInfo) {
if (notification.userInfo) { NSDictionary *userInfo1 = [notification.userInfo valueForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
if (userInfo1.count > 0) {
if ([notification.userInfo valueForKey:UIApplicationLaunchOptionsRemoteNotificationKey]) { [NSTimer scheduledTimerWithTimeInterval:0.01 target:self selector:@selector(fireOpenNotification:) userInfo:userInfo1 repeats:YES];
[JPushPlugin fireDocumentEvent:JPushDocumentEvent_OpenNotification jsString:[notification.userInfo toJsonString]]; }
}
NSDictionary *userInfo2 = [notification.userInfo valueForKey:UIApplicationLaunchOptionsLocalNotificationKey];
if ([notification.userInfo valueForKey:UIApplicationLaunchOptionsLocalNotificationKey]) { if (userInfo2.count > 0) {
UILocalNotification *localNotification = [notification.userInfo valueForKey:UIApplicationLaunchOptionsLocalNotificationKey]; [NSTimer scheduledTimerWithTimeInterval:0.01 target:self selector:@selector(fireOpenNotification:) userInfo:userInfo2 repeats:YES];
}
NSDictionary* localNotificationEvent = @{@"content":localNotification.alertBody, }
@"badge": @(localNotification.applicationIconBadgeNumber), [JPUSHService setDebugMode];
@"extras":localNotification.userInfo,
}; NSString *plistPath = [[NSBundle mainBundle] pathForResource:JPushConfig_FileName ofType:@"plist"];
[JPushPlugin fireDocumentEvent:JPushDocumentEvent_OpenNotification jsString:[localNotificationEvent toJsonString]]; NSMutableDictionary *plistData = [[NSMutableDictionary alloc] initWithContentsOfFile:plistPath];
} NSNumber *delay = [plistData valueForKey:JPushConfig_Delay];
}
_launchOptions = notification.userInfo;
[JPUSHService setDebugMode];
if (![delay boolValue]) {
NSString *plistPath = [[NSBundle mainBundle] pathForResource:JPushConfig_FileName ofType:@"plist"]; [self startJPushSDK];
NSMutableDictionary *plistData = [[NSMutableDictionary alloc] initWithContentsOfFile:plistPath]; }
NSNumber *delay = [plistData valueForKey:JPushConfig_Delay]; }
}
_launchOptions = notification.userInfo;
-(void)startJPushSDK{
if (![delay boolValue]) { [self registerForRemoteNotification];
[self startJPushSDK]; [JPushPlugin setupJPushSDK:_launchOptions];
} }
}
} -(void)registerForRemoteNotification{
if ([[UIDevice currentDevice].systemVersion floatValue] >= 10.0) {
-(void)startJPushSDK{ #ifdef NSFoundationVersionNumber_iOS_9_x_Max
[self registerForRemoteNotification]; JPUSHRegisterEntity * entity = [[JPUSHRegisterEntity alloc] init];
[JPushPlugin setupJPushSDK:_launchOptions]; entity.types = UNAuthorizationOptionAlert|UNAuthorizationOptionBadge|UNAuthorizationOptionSound;
} [JPUSHService registerForRemoteNotificationConfig:entity delegate:self];
#endif
- (void)jpushSDKDidLoginNotification { }else if ([[UIDevice currentDevice].systemVersion floatValue] >= 8.0) {
NSDictionary *event = @{@"registrationId": JPUSHService.registrationID}; //可以添加自定义categories
[JPushPlugin fireDocumentEvent:JPushDocumentEvent_receiveRegistrationId jsString:[event toJsonString]]; [JPUSHService registerForRemoteNotificationTypes:(UIUserNotificationTypeBadge |
} UIUserNotificationTypeSound |
UIUserNotificationTypeAlert)
-(void)registerForRemoteNotification{ categories:nil];
if ([[UIDevice currentDevice].systemVersion floatValue] >= 10.0) { } else if([[UIDevice currentDevice].systemVersion floatValue] < 8.0){
#ifdef NSFoundationVersionNumber_iOS_9_x_Max //categories 必须为nil
JPUSHRegisterEntity * entity = [[JPUSHRegisterEntity alloc] init]; [JPUSHService registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge |
entity.types = UNAuthorizationOptionAlert|UNAuthorizationOptionBadge|UNAuthorizationOptionSound; UIRemoteNotificationTypeSound |
[JPUSHService registerForRemoteNotificationConfig:entity delegate:self]; UIRemoteNotificationTypeAlert)
#endif categories:nil];
}else if ([[UIDevice currentDevice].systemVersion floatValue] >= 8.0) { }
//可以添加自定义categories }
[JPUSHService registerForRemoteNotificationTypes:(UIUserNotificationTypeBadge |
UIUserNotificationTypeSound | - (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
UIUserNotificationTypeAlert) [JPUSHService registerDeviceToken:deviceToken];
categories:nil]; }
} else if([[UIDevice currentDevice].systemVersion floatValue] < 8.0){
//categories 必须为nil -(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo{
[JPUSHService registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge | [JPUSHService handleRemoteNotification:userInfo];
UIRemoteNotificationTypeSound |
UIRemoteNotificationTypeAlert) [JPushPlugin fireDocumentEvent:JPushDocumentEvent_ReceiveNotification jsString:[userInfo toJsonString]];
categories:nil]; }
}
} -(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler{
[JPUSHService handleRemoteNotification:userInfo];
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken { NSString *eventName;
[JPUSHService registerDeviceToken:deviceToken]; switch ([UIApplication sharedApplication].applicationState) {
} case UIApplicationStateInactive:
eventName = JPushDocumentEvent_OpenNotification;
-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo{ break;
[JPUSHService handleRemoteNotification:userInfo]; case UIApplicationStateActive:
eventName = JPushDocumentEvent_ReceiveNotification;
[JPushPlugin fireDocumentEvent:JPushDocumentEvent_ReceiveNotification jsString:[userInfo toJsonString]]; break;
} case UIApplicationStateBackground:
eventName = JPushDocumentEvent_BackgroundNotification;
-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler{ break;
[JPUSHService handleRemoteNotification:userInfo]; default:
NSString *eventName; break;
switch ([UIApplication sharedApplication].applicationState) { }
case UIApplicationStateInactive: [JPushPlugin fireDocumentEvent:eventName jsString:[userInfo toJsonString]];
eventName = JPushDocumentEvent_OpenNotification; dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(30 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
break; completionHandler(UIBackgroundFetchResultNewData);
case UIApplicationStateActive: });
eventName = JPushDocumentEvent_ReceiveNotification; }
break;
case UIApplicationStateBackground: -(void)jpushNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(NSInteger))completionHandler{
eventName = JPushDocumentEvent_BackgroundNotification; NSMutableDictionary *userInfo = [NSMutableDictionary dictionaryWithDictionary:notification.request.content.userInfo];
break; [JPushPlugin fireDocumentEvent:JPushDocumentEvent_ReceiveNotification jsString:[userInfo toJsonString]];
default: completionHandler(UNNotificationPresentationOptionBadge|UNNotificationPresentationOptionSound|UNNotificationPresentationOptionAlert);
break; }
}
[JPushPlugin fireDocumentEvent:eventName jsString:[userInfo toJsonString]]; -(void)jpushNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)())completionHandler{
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(30 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ NSMutableDictionary *userInfo = [NSMutableDictionary dictionaryWithDictionary:response.notification.request.content.userInfo];
completionHandler(UIBackgroundFetchResultNewData); @try {
}); [userInfo setValue:[response valueForKey:@"userText"] forKey:@"userText"];
} } @catch (NSException *exception) { }
[userInfo setValue:response.actionIdentifier forKey:@"actionIdentifier"];
-(void)jpushNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(NSInteger))completionHandler{ [JPushPlugin fireDocumentEvent:JPushDocumentEvent_OpenNotification jsString:[userInfo toJsonString]];
NSMutableDictionary *userInfo = [NSMutableDictionary dictionaryWithDictionary:notification.request.content.userInfo]; completionHandler();
[JPushPlugin fireDocumentEvent:JPushDocumentEvent_ReceiveNotification jsString:[userInfo toJsonString]]; }
completionHandler(UNNotificationPresentationOptionBadge|UNNotificationPresentationOptionSound|UNNotificationPresentationOptionAlert);
} - (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification {
[[NSNotificationCenter defaultCenter] postNotificationName:JPushDocumentEvent_ReceiveLocalNotification object:notification.userInfo];
-(void)jpushNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)())completionHandler{ }
NSMutableDictionary *userInfo = [NSMutableDictionary dictionaryWithDictionary:response.notification.request.content.userInfo];
@try { - (void)applicationWillEnterForeground:(UIApplication *)application {
[userInfo setValue:[response valueForKey:@"userText"] forKey:@"userText"]; // [application setApplicationIconBadgeNumber:0];
} @catch (NSException *exception) { } // [application cancelAllLocalNotifications];
[userInfo setValue:response.actionIdentifier forKey:@"actionIdentifier"]; }
[JPushPlugin fireDocumentEvent:JPushDocumentEvent_OpenNotification jsString:[userInfo toJsonString]];
completionHandler(); - (void)applicationDidEnterBackground:(UIApplication *)application {
} // [[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];
}
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification {
NSDictionary* localNotificationEvent = @{@"content":notification.alertBody, @end
@"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
+2 -1
View File
@@ -27,6 +27,7 @@ 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";
+103 -102
View File
@@ -1,102 +1,103 @@
// //
// PushTalkPlugin.h // PushTalkPlugin.h
// PushTalk // PushTalk
// //
// Created by zhangqinghe on 13-12-13. // Created by zhangqinghe on 13-12-13.
// //
// //
#import <Cordova/CDV.h> #import <Cordova/CDV.h>
static NSMutableDictionary *_jpushEventCache; @interface JPushPlugin : CDVPlugin{
@interface JPushPlugin : CDVPlugin{ }
} //注册通知服务并启动 SDK
-(void)startJPushSDK:(CDVInvokedUrlCommand*)command;
//注册通知服务并启动 SDK
-(void)startJPushSDK:(CDVInvokedUrlCommand*)command; //以下为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;
-(void)cleanTags:(CDVInvokedUrlCommand*)command; -(void)cleanTags:(CDVInvokedUrlCommand*)command;
-(void)getAllTags:(CDVInvokedUrlCommand*)command; -(void)getAllTags:(CDVInvokedUrlCommand*)command;
-(void)checkTagBindState:(CDVInvokedUrlCommand*)command; -(void)checkTagBindState:(CDVInvokedUrlCommand*)command;
-(void)setAlias:(CDVInvokedUrlCommand*)command; -(void)setAlias:(CDVInvokedUrlCommand*)command;
-(void)deleteAlias:(CDVInvokedUrlCommand*)command; -(void)deleteAlias:(CDVInvokedUrlCommand*)command;
-(void)getAlias:(CDVInvokedUrlCommand*)command; -(void)getAlias:(CDVInvokedUrlCommand*)command;
//获取 RegistrationID //获取 RegistrationID
-(void)getRegistrationID:(CDVInvokedUrlCommand*)command; -(void)getRegistrationID:(CDVInvokedUrlCommand*)command;
//页面统计 //页面统计
-(void)startLogPageView:(CDVInvokedUrlCommand*)command; -(void)startLogPageView:(CDVInvokedUrlCommand*)command;
-(void)stopLogPageView:(CDVInvokedUrlCommand*)command; -(void)stopLogPageView:(CDVInvokedUrlCommand*)command;
-(void)beginLogPageView:(CDVInvokedUrlCommand*)command; -(void)beginLogPageView:(CDVInvokedUrlCommand*)command;
//设置角标到服务器,服务器下一次发消息时,会设置成这个值 //设置角标到服务器,服务器下一次发消息时,会设置成这个值
//本接口不会改变应用本地的角标值. //本接口不会改变应用本地的角标值.
-(void)setBadge:(CDVInvokedUrlCommand*)command; -(void)setBadge:(CDVInvokedUrlCommand*)command;
//相当于 [setBadge:0] //相当于 [setBadge:0]
-(void)resetBadge:(CDVInvokedUrlCommand*)command; -(void)resetBadge:(CDVInvokedUrlCommand*)command;
//应用本地的角标值设置/获取 //应用本地的角标值设置/获取
-(void)setApplicationIconBadgeNumber:(CDVInvokedUrlCommand*)command; -(void)setApplicationIconBadgeNumber:(CDVInvokedUrlCommand*)command;
-(void)getApplicationIconBadgeNumber:(CDVInvokedUrlCommand*)command; -(void)getApplicationIconBadgeNumber:(CDVInvokedUrlCommand*)command;
//停止与恢复推送 //停止与恢复推送
-(void)stopPush:(CDVInvokedUrlCommand*)command; -(void)stopPush:(CDVInvokedUrlCommand*)command;
-(void)resumePush:(CDVInvokedUrlCommand*)command; -(void)resumePush:(CDVInvokedUrlCommand*)command;
-(void)isPushStopped:(CDVInvokedUrlCommand*)command; -(void)isPushStopped:(CDVInvokedUrlCommand*)command;
//开关日志 //开关日志
-(void)setDebugModeFromIos:(CDVInvokedUrlCommand*)command; -(void)setDebugModeFromIos:(CDVInvokedUrlCommand*)command;
-(void)setLogOFF:(CDVInvokedUrlCommand*)command; -(void)setLogOFF:(CDVInvokedUrlCommand*)command;
-(void)crashLogON:(CDVInvokedUrlCommand*)command; -(void)crashLogON:(CDVInvokedUrlCommand*)command;
//本地推送 //本地推送
-(void)setLocalNotification:(CDVInvokedUrlCommand*)command; -(void)setLocalNotification:(CDVInvokedUrlCommand*)command;
-(void)deleteLocalNotificationWithIdentifierKey:(CDVInvokedUrlCommand*)command; -(void)deleteLocalNotificationWithIdentifierKey:(CDVInvokedUrlCommand*)command;
-(void)clearAllLocalNotifications:(CDVInvokedUrlCommand*)command; -(void)clearAllLocalNotifications:(CDVInvokedUrlCommand*)command;
//地理位置上报 [latitude,longitude] //地理位置上报 [latitude,longitude]
-(void)setLocation:(CDVInvokedUrlCommand*)command; -(void)setLocation:(CDVInvokedUrlCommand*)command;
//检查用户的推送设置情况 //检查用户的推送设置情况
-(void)getUserNotificationSettings:(CDVInvokedUrlCommand*)command; -(void)getUserNotificationSettings:(CDVInvokedUrlCommand*)command;
//ios 10 APIs //ios 10 APIs
-(void)addDismissActions:(CDVInvokedUrlCommand*)command; -(void)addDismissActions:(CDVInvokedUrlCommand*)command;
-(void)addNotificationActions:(CDVInvokedUrlCommand*)command; -(void)addNotificationActions:(CDVInvokedUrlCommand*)command;
/* /*
* 以下为js中可监听到的事件 * 以下为js中可监听到的事件
* jpush.openNotification 点击推送消息启动或唤醒app * jpush.openNotification 点击推送消息启动或唤醒app
* jpush.receiveMessage 收到自定义消息 * jpush.setTagsWithAlias 设置标签、别名完成
* jpush.receiveNotification 前台收到推送 * jpush.receiveMessage 收到自定义消息
* jpush.backgroundNotification 台收到推送 * jpush.receiveNotification 台收到推送
*/ * jpush.backgroundNotification 后台收到推送
*/
# pragma mark - private
# pragma mark - private
+(void)fireDocumentEvent:(NSString*)eventName jsString:(NSString*)jsString;
+(void)fireDocumentEvent:(NSString*)eventName jsString:(NSString*)jsString;
+(void)setupJPushSDK:(NSDictionary*)userInfo;
+(void)setupJPushSDK:(NSDictionary*)userInfo;
@end
@end
static JPushPlugin *SharedJPushPlugin;
JPushPlugin *SharedJPushPlugin;
@interface NSDictionary (JPush)
-(NSString*)toJsonString; @interface NSDictionary (JPush)
@end -(NSString*)toJsonString;
@end
@interface NSString (JPush)
-(NSDictionary*)toDictionary; @interface NSString (JPush)
@end -(NSDictionary*)toDictionary;
@end
File diff suppressed because it is too large Load Diff
+1 -1
View File
@@ -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.7 #define JPUSH_VERSION_NUMBER 3.0.6
#import <Foundation/Foundation.h> #import <Foundation/Foundation.h>
+14
View File
@@ -70,6 +70,20 @@ 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)
}
/** /**
* 设置标签。 * 设置标签。
* 注意:该接口是覆盖逻辑,而不是增量逻辑。即新的调用会覆盖之前的设置。 * 注意:该接口是覆盖逻辑,而不是增量逻辑。即新的调用会覆盖之前的设置。