Compare commits

...

29 Commits

Author SHA1 Message Date
huangminlinux 4b929a8e2e update 3.2.12 2017-11-08 13:56:14 +08:00
huangminlinux d3e2e1a5d7 fix app not launch open notification bug 2017-11-08 13:49:50 +08:00
Hevin 001ab96283 Fix error words 2017-11-03 17:37:48 +08:00
huangminlinux 1314d33c62 udpate docs 2017-11-03 17:13:52 +08:00
huangminlinux 22b6d9a006 adjust glable var to static 2017-11-01 16:29:27 +08:00
Hevin 0cbedb412c Format api doc 2017-10-27 14:29:43 +08:00
Hevin fbd9d63590 build: v3.2.11 2017-10-25 11:19:14 +08:00
huangminlinux 184ee01d1d update registrationId evet 2017-10-25 11:09:46 +08:00
huangminlinux 14a40c6572 adjust ios registerNotification event 2017-10-25 10:49:58 +08:00
Hevin fefaaea14f build: v3.2.10 2017-10-23 17:22:53 +08:00
huangminlinux d2f9959ae1 open notification event add to jpush event cache 2017-10-23 17:18:49 +08:00
huangminlinux 3129165d3f add jpush event cache 2017-10-23 17:11:35 +08:00
Hevin 66932a8bc8 build: v3.2.9 2017-10-20 13:09:32 +08:00
huangminlinux 07c9b2b945 fix iOS10 remove local notification fail bug 2017-10-20 11:28:51 +08:00
huangminlinux 8811dfc002 update docs 2017-10-19 13:51:19 +08:00
Hevin 0ee5f8b1a0 Update iOS SDK to v3.0.7 2017-10-13 13:10:47 +08:00
Hevin 259ec0a03a Update API doc 2017-10-13 13:09:19 +08:00
Hevin 6283cb26f6 Remove deprecated method
setTagsWithAlias
2017-10-13 10:12:16 +08:00
Hevin 1c3228848b build: v3.2.7 2017-10-11 14:49:07 +08:00
huangminlinux 585e2a5084 fix open local notification to launch app event bug 2017-10-11 14:28:56 +08:00
huangminlinux c726477cfb remove jpush.startLocalNotification event in iOS docs 2017-10-11 11:29:40 +08:00
huangminlinux 3f00143a5a update doc remove startLocalNotification event 2017-10-11 11:26:46 +08:00
huangminlinux f5ea2b5b10 ios add jpush.receiveRegistrationId event 2017-10-11 11:15:13 +08:00
Hevin 266d0cb28f Add JPushEventReceiver in manifest 2017-09-28 10:22:40 +08:00
Hevin 9f156727e7 Remove unused code 2017-09-26 17:51:25 +08:00
Hevin 155f1e2f6c Update Android SDK to v3.0.9 2017-09-26 17:48:18 +08:00
Hevin 9680e685e3 Remove unused console.log 2017-09-25 12:33:08 +08:00
Hevin 2eefd1c247 Fixed android api doc 2017-09-25 12:32:27 +08:00
Hevin fa256bfb46 Format api doc 2017-09-23 09:11:21 +08:00
16 changed files with 943 additions and 945 deletions
+2 -2
View File
@@ -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.4-blue.svg)](https://github.com/jpush/jpush-phonegap-plugin/releases)
[![release](https://img.shields.io/badge/release-3.2.12-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)
@@ -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 开关。
+6 -46
View File
@@ -1,12 +1,5 @@
# Android API 简介
- [注册成功事件](#注册成功事件)
- [接收通知时获得通知的内容](#接收通知时获得通知的内容)
- [打开通知时获得通知的内容](#打开通知时获得通知的内容)
- [收到自定义消息时获取消息的内容](#收到自定义消息时获取消息的内容)
- [获取集成日志(同时适用于 iOS](#获取集成日志同时适用于-ios)
- [接收消息和点击通知事件](#接收消息和点击通知事件)
- [统计分析](#统计分析)
- [清除通知](#清除通知)
- [设置允许推送时间](#设置允许推送时间)
- [设置通知静默时间](#设置通知静默时间)
@@ -14,44 +7,6 @@
- [设置保留最近通知条数](#设置保留最近通知条数)
- [本地通知](#本地通知)
## 注册成功事件
### jpush.receiveRegistrationId
集成了 JPush SDK 的应用程序在第一次成功注册到 JPush 服务器时,JPush 服务器会给客户端返回一个唯一的该设备的标识 - RegistrationID。
就会触发这个事件(注意只有第一次会触发该事件,之后如果想要取到 registrationId,可以直接调用 *getRegistrationID* 方法)。
#### 代码示例
```js
document.addEventListener('jpush.receiveRegistrationId', function (event) {
console.log(event.registrationId)
}, false)
```
## 接收通知时获得通知的内容
- 内容:
window.JPush.receiveNotification.alert
- 标题:
window.JPush.receiveNotification.title
- 附加字段:
window.JPush.receiveNotification.extras.yourKey
## 打开通知时获得通知的内容
- 内容:
window.JPush.openNotification.alert
- 标题:
window.JPush.openNotification.title
- 附加字段
window.JPush.openNotification.extras.yourKey
## 收到自定义消息时获取消息的内容
- 内容:
window.JPush.receiveMessage.message
- 附加字段:
window.JPush.receiveMessage.extras.yourKey
## 获取集成日志(同时适用于 iOS)
### API - setDebugMode
@@ -133,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)。
@@ -159,6 +114,11 @@ window.JPush.setSilenceTime(startHour, startMinute, endHour, endMinute)
## 通知栏样式定制
目前 REST API 与极光控制台均已支持「大文本通知栏样」、「文本条目通知栏样式」和「大图片通知栏样式」。可直接推送对应样式
的通知。
此外也能够通过设置 Notification 的 flag 来控制通知提醒方式,具体用法可参考 [后台 REST API](https://docs.jiguang.cn/jpush/server/push/rest_api_v3_push/#notification)。
### API - setBasicPushNotificationBuilder, setCustomPushNotificationBuilder
当用户需要定制默认的通知栏样式时,则可调用此方法。
+54 -19
View File
@@ -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
@@ -528,11 +561,13 @@ document.addEventListener("jpush.receiveMessage", function (event) {
在 iOS 中,返回值为 0 时,代表系统设置中关闭了推送;大于 0 时,代表打开了推送,且能够根据返回值判断具体通知形式:
```js
UIRemoteNotificationTypeNone = 0, // 0
UIRemoteNotificationTypeBadge = 1 << 0, // 1
UIRemoteNotificationTypeSound = 1 << 1, // 2
UIRemoteNotificationTypeAlert = 1 << 2, // 4
UIRemoteNotificationTypeNewsstandContentAvailability = 1 << 3 // 8
```
#### 代码示例
@@ -543,4 +578,4 @@ window.JPush.getUserNotificationSettings(function(result) {
} else if(result > 0) {
// 系统设置中打开了应用推送。
})
```
```
+1 -11
View File
@@ -143,7 +143,7 @@ window.JPush.getRegistrationID(function(data) {
#### event - jpush.openNotification
点击通知启动或唤醒应用程序时会发该事件
点击通知启动或唤醒应用程序时会发该事件
#### 代码示例
@@ -437,9 +437,7 @@ window.JPush.clearAllLocalNotifications()
监听 [jpush.receiveNotification](#前台收到推送)、[jpush.openNotification](点击推送通知),获取推送内容后,通过获取到的 `__JPUSHNotificationKey` 字段([本地通知](#本地通知) 设置的 `notificationID`)来判断是本地通知,并处理。
### 点击本地通知横幅启动 App
监听 `jpush.startLocalNotification` 事件。
## 页面的统计
@@ -718,18 +716,10 @@ window.JPush.getUserNotificationSettings(callback)
[iOS 7 以后后台收到远程通知](#后台收到推送)
### jpush.setTagsWithAlias
[设置标签别名回调](#返回值说明)
### jpush.receiveMessage
[获取自定义消息内容](#获取自定义消息内容)
### jpush.startLocalNotification
[点击本地通知横幅启动 App](#点击本地通知横幅启动-app)
### jpush.receiveLocalNotification
[iOS 10 before 收到本地通知](#ios-10-before-收到本地通知)
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "jpush-phonegap-plugin",
"version": "3.2.4",
"version": "3.2.12",
"description": "JPush for cordova plugin",
"cordova": {
"id": "jpush-phonegap-plugin",
+22 -7
View File
@@ -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.4">
version="3.2.12">
<name>JPush</name>
<description>JPush for cordova plugin</description>
@@ -38,7 +38,7 @@
<source-file src="src/ios/Plugins/AppDelegate+JPush.m" />
<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" />
<framework src="CFNetwork.framework" weak="true" />
@@ -72,20 +72,22 @@
<config-file target="AndroidManifest.xml" parent="/manifest">
<!-- Required 一些系统要求的权限,如访问网络等-->
<permission android:name="$PACKAGE_NAME.permission.JPUSH_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="$PACKAGE_NAME.permission.JPUSH_MESSAGE" />
<uses-permission android:name="android.permission.RECEIVE_USER_PRESENT" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_SETTINGS" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
<uses-permission android:name="android.permission.WRITE_SETTINGS" />
<permission android:name="$PACKAGE_NAME.permission.JPUSH_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
</config-file>
<config-file target="AndroidManifest.xml" parent="/manifest/application">
@@ -187,12 +189,25 @@
android:name="cn.jpush.android.service.AlarmReceiver"
android:exported="false" />
<!-- since 3.0.9 Required SDK 核心功能-->
<provider
android:authorities="$PACKAGE_NAME.DataProvider"
android:name="cn.jpush.android.service.DataProvider"
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 -->
<meta-data android:name="JPUSH_CHANNEL" android:value="developer-default" />
<meta-data android:name="JPUSH_APPKEY" android:value="$APP_KEY" />
</config-file>
<source-file src="src/android/libs/jpush-android-3.0.8.jar" target-dir="libs" />
<source-file src="src/android/libs/jpush-android-3.0.9.jar" target-dir="libs" />
<source-file src="src/android/MyReceiver.java" target-dir="src/cn/jiguang/cordova/push" />
<source-file src="src/android/JPushPlugin.java" target-dir="src/cn/jiguang/cordova/push" />
+3 -45
View File
@@ -39,15 +39,12 @@ import cn.jpush.android.service.JPushMessageReceiver;
public class JPushPlugin extends CordovaPlugin {
private ExecutorService threadPool = Executors.newFixedThreadPool(1);
private static final String TAG = JPushPlugin.class.getSimpleName();
private Context mContext;
private static JPushPlugin instance;
private static Activity cordovaActivity;
private static String TAG = "JPushPlugin";
private static boolean isStatisticsOpened = false; // 是否开启统计分析功能
static String notificationTitle;
static String notificationAlert;
@@ -85,16 +82,7 @@ public class JPushPlugin extends CordovaPlugin {
}
}
public void onPause(boolean multitasking) {
if (isStatisticsOpened && multitasking) {
JPushInterface.onPause(this.cordova.getActivity());
}
}
public void onResume(boolean multitasking) {
if (isStatisticsOpened && multitasking) {
JPushInterface.onResume(this.cordova.getActivity());
}
if (openNotificationAlert != null) {
notificationAlert = null;
transmitNotificationOpen(openNotificationTitle, openNotificationAlert,
@@ -252,7 +240,7 @@ public class JPushPlugin extends CordovaPlugin {
@Override
public boolean execute(final String action, final JSONArray data,
final CallbackContext callbackContext) throws JSONException {
threadPool.execute(new Runnable() {
cordova.getThreadPool().execute(new Runnable() {
@Override
public void run() {
try {
@@ -539,24 +527,6 @@ public class JPushPlugin extends CordovaPlugin {
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) {
boolean isConnected = JPushInterface.getConnectionState(cordovaActivity.getApplicationContext());
callback.success(String.valueOf(isConnected));
@@ -565,8 +535,7 @@ public class JPushPlugin extends CordovaPlugin {
/**
* 自定义通知行为声音震动呼吸灯等
*/
void setBasicPushNotificationBuilder(JSONArray data,
CallbackContext callbackContext) {
void setBasicPushNotificationBuilder(JSONArray data, CallbackContext callbackContext) {
BasicPushNotificationBuilder builder = new BasicPushNotificationBuilder(
this.cordova.getActivity());
builder.developerArg0 = "Basic builder 1";
@@ -644,17 +613,6 @@ public class JPushPlugin extends CordovaPlugin {
JPushInterface.clearLocalNotifications(this.cordova.getActivity());
}
/**
* 决定是否启用统计分析功能
*/
void setStatisticsOpen(JSONArray data, CallbackContext callbackContext) {
try {
isStatisticsOpened = data.getBoolean(0);
} catch (JSONException e) {
e.printStackTrace();
}
}
/**
* 设置通知静默时间
* http://docs.jpush.io/client/android_api/#api_5
Binary file not shown.
Binary file not shown.
+33 -16
View File
@@ -28,29 +28,36 @@
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{
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) {
NSDictionary *userInfo1 = [notification.userInfo valueForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
if (userInfo1.count > 0) {
[NSTimer scheduledTimerWithTimeInterval:0.01 target:self selector:@selector(fireOpenNotification:) userInfo:userInfo1 repeats:YES];
}
NSDictionary *userInfo2 = [notification.userInfo valueForKey:UIApplicationLaunchOptionsLocalNotificationKey];
if (userInfo2.count > 0) {
[NSTimer scheduledTimerWithTimeInterval:0.01 target:self selector:@selector(fireOpenNotification:) userInfo:userInfo2 repeats:YES];
}
if ([notification.userInfo valueForKey:UIApplicationLaunchOptionsRemoteNotificationKey]) {
[JPushPlugin fireDocumentEvent:JPushDocumentEvent_OpenNotification jsString:[notification.userInfo toJsonString]];
}
if ([notification.userInfo valueForKey:UIApplicationLaunchOptionsLocalNotificationKey]) {
UILocalNotification *localNotification = [notification.userInfo valueForKey:UIApplicationLaunchOptionsLocalNotificationKey];
NSDictionary* localNotificationEvent = @{@"content":localNotification.alertBody,
@"badge": @(localNotification.applicationIconBadgeNumber),
@"extras":localNotification.userInfo,
};
[JPushPlugin fireDocumentEvent:JPushDocumentEvent_OpenNotification jsString:[localNotificationEvent toJsonString]];
}
}
[JPUSHService setDebugMode];
NSString *plistPath = [[NSBundle mainBundle] pathForResource:JPushConfig_FileName ofType:@"plist"];
@@ -70,6 +77,11 @@ NSDictionary *_launchOptions;
[JPushPlugin setupJPushSDK:_launchOptions];
}
- (void)jpushSDKDidLoginNotification {
NSDictionary *event = @{@"registrationId": JPUSHService.registrationID};
[JPushPlugin fireDocumentEvent:JPushDocumentEvent_receiveRegistrationId jsString:[event toJsonString]];
}
-(void)registerForRemoteNotification{
if ([[UIDevice currentDevice].systemVersion floatValue] >= 10.0) {
#ifdef NSFoundationVersionNumber_iOS_9_x_Max
@@ -141,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 {
+1 -2
View File
@@ -27,7 +27,6 @@ static NSString *const JPushDocumentEvent_OpenNotification = @"openNoti
static NSString *const JPushDocumentEvent_BackgroundNotification = @"backgroundNotification";
static NSString *const JPushDocumentEvent_SetTagsWithAlias = @"setTagsWithAlias";
static NSString *const JPushDocumentEvent_ReceiveMessage = @"receiveMessage";
static NSString *const JPushDocumentEvent_StartLocalNotification = @"startLocalNotification";
static NSString *const JPushDocumentEvent_ReceiveLocalNotification = @"receiveLocalNotification";
static NSString *const JPushDocumentEvent_receiveRegistrationId = @"receiveRegistrationId";
+3 -4
View File
@@ -8,6 +8,8 @@
#import <Cordova/CDV.h>
static NSMutableDictionary *_jpushEventCache;
@interface JPushPlugin : CDVPlugin{
}
@@ -17,8 +19,6 @@
//以下为js中可调用接口
//设置标签、别名
-(void)setTagsWithAlias:(CDVInvokedUrlCommand*)command;
-(void)setTags:(CDVInvokedUrlCommand*)command;
-(void)addTags:(CDVInvokedUrlCommand*)command;
-(void)deleteTags:(CDVInvokedUrlCommand*)command;
@@ -76,7 +76,6 @@
/*
* js中可监听到的事件
* jpush.openNotification app
* jpush.setTagsWithAlias
* jpush.receiveMessage
* jpush.receiveNotification
* jpush.backgroundNotification
@@ -90,7 +89,7 @@
@end
JPushPlugin *SharedJPushPlugin;
static JPushPlugin *SharedJPushPlugin;
@interface NSDictionary (JPush)
-(NSString*)toJsonString;
+75 -23
View File
@@ -79,29 +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;
}
-(void)setTagsWithAlias:(CDVInvokedUrlCommand*)command{
NSString *alias = [command argumentAtIndex:0];
NSArray *tags = [command argumentAtIndex:1];
if (!_jpushEventCache) {
_jpushEventCache = @{}.mutableCopy;
}
[JPUSHService setTags:[NSSet setWithArray:tags]
alias:alias
fetchCompletionHandle:^(int iResCode, NSSet *iTags, NSString *iAlias) {
CDVPluginResult *result;
if (iResCode == 0) {
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:nil];
} else {
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:nil];
}
[self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
}];
if (!_jpushEventCache[eventName]) {
_jpushEventCache[eventName] = @[].mutableCopy;
}
[_jpushEventCache[eventName] addObject: jsString];
}
-(void)setTags:(CDVInvokedUrlCommand*)command {
@@ -364,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{
@@ -520,4 +566,10 @@
}
}
-(void)receiveLocalNotification:(NSNotification *)notification {
if (notification && notification.object) {
[JPushPlugin fireDocumentEvent:JPushDocumentEvent_ReceiveLocalNotification
jsString:[notification.object toJsonString]];
}
}
@end
+1 -1
View File
@@ -9,7 +9,7 @@
* 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>
-27
View File
@@ -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)
}
/**
* 设置标签
* 注意该接口是覆盖逻辑而不是增量逻辑即新的调用会覆盖之前的设置
@@ -311,21 +297,18 @@ JPushPlugin.prototype.receiveRegistrationIdInAndroidCallback = function (data) {
JPushPlugin.prototype.receiveMessageInAndroidCallback = function (data) {
data = JSON.stringify(data)
console.log('JPushPlugin:receiveMessageInAndroidCallback: ' + data)
this.receiveMessage = JSON.parse(data)
cordova.fireDocumentEvent('jpush.receiveMessage', this.receiveMessage)
}
JPushPlugin.prototype.openNotificationInAndroidCallback = function (data) {
data = JSON.stringify(data)
console.log('JPushPlugin:openNotificationInAndroidCallback: ' + data)
this.openNotification = JSON.parse(data)
cordova.fireDocumentEvent('jpush.openNotification', this.openNotification)
}
JPushPlugin.prototype.receiveNotificationInAndroidCallback = function (data) {
data = JSON.stringify(data)
console.log('JPushPlugin:receiveNotificationInAndroidCallback: ' + data)
this.receiveNotification = JSON.parse(data)
cordova.fireDocumentEvent('jpush.receiveNotification', this.receiveNotification)
}
@@ -368,16 +351,6 @@ JPushPlugin.prototype.reportNotificationOpened = function (msgID) {
}
}
/**
*是否开启统计分析功能用于用户使用时长活跃用户用户打开次数的统计并上报到服务器上
* Portal 上展示给开发者
*/
JPushPlugin.prototype.setStatisticsOpen = function (mode) {
if (device.platform === 'Android') {
this.callNative('setStatisticsOpen', [mode], null)
}
}
/**
* 用于在 Android 6.0 及以上系统申请一些权限
* 具体可看http://docs.jpush.io/client/android_api/#android-60