Compare commits

..

75 Commits

Author SHA1 Message Date
Hevin
7a4943e820 Merge branch 'dev' 2017-12-15 16:27:39 +08:00
Hevin
579e2b6de3 Update FAQ 2017-12-15 16:27:14 +08:00
Hevin
05b3fb1b82 Merge branch 'dev' 2017-12-15 16:04:25 +08:00
Hevin
5301a2c5ea Update ionic install script 2017-12-15 15:35:28 +08:00
Hevin
d628cc168b Change the format 2017-12-15 15:01:09 +08:00
Hevin
cce897daa0 Update install step of ionic 2017-12-15 14:50:38 +08:00
Hevin
0449935bcb Update example 2017-12-14 17:16:00 +08:00
Hevin
b730924d74 Fixed extras to object of addLocalNotificationForIOS 2017-12-14 16:47:08 +08:00
huangminlinux
4780eafb72 adjust ios remote notification formate 2017-12-14 15:36:43 +08:00
huangminlinux
53e3588937 fix conflict 2017-12-14 11:03:33 +08:00
huangminlinux
4585a13d7b update localnotification event field 2017-12-13 13:32:34 +08:00
huangminlinux
f50a8ea5c7 fix local notification event in ios 10 2017-12-12 17:00:28 +08:00
huangminlinux
9ea65add1f update demo add receiveLocalNotification Event 2017-12-12 14:26:55 +08:00
huangminlinux
9c103753e6 update iOS docs 2017-12-12 14:20:04 +08:00
Hevin
3f1fa1e7ba Merge branch 'ionic' into dev 2017-12-11 19:06:43 +08:00
Hevin
c0c7d904e3 Complete example 2017-12-11 19:06:04 +08:00
Hevin
509184328d Fix params type error 2017-12-11 18:44:33 +08:00
Hevin
a0c828a296 Update gitignore 2017-12-11 15:22:11 +08:00
Hevin
2d81c7800b Merge branch 'ionic' into dev 2017-12-11 13:21:35 +08:00
Hevin
4cfca93789 Complete ionic example 2017-12-11 13:02:50 +08:00
Hevin
c254794ace create ionic floder 2017-12-11 12:31:54 +08:00
Hevin
6d013438cd Fixed checkTagBindState callback error 2017-12-08 21:38:40 +08:00
Hevin
29970cd306 Fixed params error 2017-12-08 21:35:42 +08:00
Hevin
4f4a7e44f8 build ionic-native/jpush 2017-12-07 21:35:43 +08:00
Hevin
a891578f74 Complete index.ts 2017-12-07 21:32:48 +08:00
Hevin
07c9722551 Merge branch 'dev' into ionic 2017-12-04 13:33:16 +08:00
Hevin
f6ece7dd1e Merge branch 'dev' 2017-12-04 13:32:54 +08:00
Hevin
0b4f328e19 Update FAQ 2017-12-04 13:31:33 +08:00
Hevin
bb7b810215 Add ionic-native 2017-11-27 20:36:41 +08:00
Hevin
5bea9b0bac Merge branch 'dev' into ionic 2017-11-27 15:17:41 +08:00
Hevin
7470258950 Update Android sdk to 3.1.0 2017-11-27 15:17:18 +08:00
Hevin
46f5f41f8e Merge branch 'dev' into ionic 2017-11-27 12:55:01 +08:00
Hevin
a33cc11090 Make jcore version explitily 2017-11-27 12:54:49 +08:00
Hevin
c4e2deec06 Remove unused methods 2017-11-14 10:56:54 +08:00
huangminlinux
b282d70b2f Merge pull request #287 from jpush/dev
change arrow syntax to function
2017-11-08 03:05:43 -06:00
huangminlinux
a0752562b5 fix demo 2017-11-08 17:04:06 +08:00
huangminlinux
82c6532d12 Merge pull request #286 from jpush/dev
update to 3.2.12
2017-11-07 23:58:22 -06:00
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
b8f79dd130 Merge branch 'dev' 2017-11-03 17:38:08 +08:00
Hevin
001ab96283 Fix error words 2017-11-03 17:37:48 +08:00
huangminlinux
1e2a4ce0e4 Merge pull request #284 from jpush/dev
update docs
2017-11-03 04:14:25 -05: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
c708f396bd Merge branch 'dev' 2017-10-27 14:29:56 +08:00
Hevin
0cbedb412c Format api doc 2017-10-27 14:29:43 +08:00
Hevin
8b2a0daecc Merge branch 'dev' 2017-10-25 11:19:39 +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
469af4fcd3 Merge branch 'dev' 2017-10-23 17:23:10 +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
494df2e527 Merge branch 'dev' 2017-10-20 13:10:03 +08:00
Hevin
66932a8bc8 build: v3.2.9 2017-10-20 13:09:32 +08:00
Hevin
031acb9631 Merge branch 'dev' 2017-10-13 13:11:12 +08:00
Hevin
8d098d29b1 Merge branch 'dev' 2017-10-11 14:49:23 +08:00
huangminlinux
a9343ac776 Merge pull request #278 from jpush/dev
fix open local notification to launch app event bug
2017-10-11 01:43:19 -05:00
huangminlinux
de58071773 Merge pull request #277 from jpush/dev
remove jpush.startLocalNotification event in iOS docs
2017-10-10 22:30:56 -05:00
huangminlinux
13341fd68a Merge pull request #276 from jpush/dev
Dev
2017-10-10 22:28:05 -05:00
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
27 changed files with 1190 additions and 179 deletions

30
.gitignore vendored
View File

@@ -36,4 +36,34 @@ Network Trash Folder
Temporary Items
.apdisk
# Ionic example
ionic/example/.sourcemaps/*
ionic/example/node_modules/*
ionic/example/plugins/*
ionic/example/config.xml
ionic/example/ionic.config.json
ionic/example/package-lock.json
ionic/example/package.json
ionic/example/tsconfig.json
ionic/example/tslint.json
ionic/example/resources/README\.md
ionic/example/www/*
ionic/example/src/assets/*
ionic/example/src/theme
ionic/example/platforms
ionic/example/src/manifest\.json
ionic/example/resources/android/splash/
ionic/example/resources/
ionic/example/src/service-worker\.js
ionic/example/src/index\.html
ionic/example/src/app/app\.scss
ionic/example/src/app/main\.ts
# End of https://www.gitignore.io/api/macos,apachecordova

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.8-blue.svg)](https://github.com/jpush/jpush-phonegap-plugin/releases)
[![release](https://img.shields.io/badge/release-3.2.13-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,10 +28,32 @@
- 或下载到本地安装:
```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 开关。
### Ionic
如果使用了 Ionic可以再安装 @jiguang-ionic/jpush 包,适配 ionic-native
```shell
npm install --save @jiguang-ionic/jpush
```
然后在 *app.module.ts* 中增加:
```js
import { JPush } from '@jiguang-ionic/jpush';
...
providers: [
...
JPush,
...
]
```
具体可参考 ./ionic/example 中的文件。
> 在使用 Xcode 8 或以上调试 iOS 项目时,需要先在项目配置界面的 Capabilities 中打开 Push Notifications 开关。
## Usage
@@ -72,14 +94,13 @@
Android 因为各 Rom 的高度定制化,不像 iOS 一样能有一个统一的管理,如果在 Android 中想自定义通知铃声,推荐通过 JPush 推送自定义
消息,之后在 `jpush.receiveMessage` 事件监听中通过 [Cordova Local-Notification Plugin](https://github.com/katzer/cordova-plugin-local-notifications) 触发通知,再配合 [Cordova Background Plugin](https://github.com/katzer/cordova-plugin-background-mode) 插件保证应用的后台运行。
#### 如让通知内容像 iOS 一样换行展示?
#### 如让通知内容像 iOS 一样自动换行展示?
[#267](https://github.com/jpush/jpush-phonegap-plugin/issues/267)
#### 关闭 App 后收不到通知
Android 的推送通过长连接的方式实现,只有在连接保持的情况下才能收到通知。而有的第三方 ROM 会限制一般应用服务的自启动,也就是
在退出应用后,应用的所有服务均被杀死,且无法自启动,所以就会收不到通知。
Android 的推送通过长连接的方式实现,只有在保持连接的情况下才能收到通知。而有的第三方 ROM 会限制一般应用服务的自启动,也就是在退出应用后,应用的所有服务均被杀死,且无法自启动,所以就会收不到通知。
目前 JPush 是做了应用互相拉起机制的,也就是当用户打开其他集成了 JPush 的应用时,你的应用也能同时收到推送消息。
@@ -98,10 +119,6 @@ Android 的推送通过长连接的方式实现,只有在连接保持的情况
cordova platform update ios
```
#### ionic 2 如何调用 API
[issue 179](https://github.com/jpush/jpush-phonegap-plugin/issues/179)
#### PushConfig.plist 文件中的字段都是什么意思?
- Appkey应用标识。

View File

@@ -1,7 +1,5 @@
# Android API 简介
- [注册成功事件](#注册成功事件)
- [获取集成日志(同时适用于 iOS](#获取集成日志同时适用于-ios)
- [清除通知](#清除通知)
- [设置允许推送时间](#设置允许推送时间)
- [设置通知静默时间](#设置通知静默时间)

View File

@@ -1,20 +1,40 @@
# 通用 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)
- [判断系统设置中是否允许当前应用推送](#判断系统设置中是否允许当前应用推送)
## 注册成功事件
### jpush.receiveRegistrationId
集成了 JPush SDK 的应用程序在第一次成功注册到 JPush 服务器时JPush 服务器会给客户端返回一个唯一的该设备的标识 - RegistrationID。
就会触发这个事件(注意只有第一次会触发该事件,之后如果想要取到 registrationId可以直接调用 *getRegistrationID* 方法)。
集成了 JPush SDK 的应用程序在第一次成功注册到 JPush 服务器时JPush 服务器会给客户端返回一个唯一的该设备的标识 - Registration ID。
此时就会触发这个事件(注意只有第一次会触发该事件,之后如果想要取到 Registration Id可以直接调用 `getRegistrationID` 方法)。
#### 代码示例
@@ -24,9 +44,9 @@ document.addEventListener('jpush.receiveRegistrationId', function (event) {
}, false)
```
## 停止与恢复推送服务
## 初始化、停止与恢复推送服务
### API - init
### init
调用此 API用来开启 JPush SDK 提供的推送服务。
@@ -44,7 +64,7 @@ document.addEventListener('jpush.receiveRegistrationId', function (event) {
window.JPush.init()
```
### API - stopPush
### stopPush
- Android:
- 开发者 App 可以通过调用停止推送服务 API 来停止极光推送服务,当又需要使用极光推送服务时,则必须要调用恢复推送服务 API。
@@ -63,7 +83,7 @@ window.JPush.init()
window.JPush.stopPush()
```
### API - resumePush
### resumePush
恢复推送服务。调用了此 API 后:
@@ -79,7 +99,7 @@ window.JPush.stopPush()
window.JPush.resumePush()
```
### API - isPushStopped
### isPushStopped
- Android 平台:
- 用来检查 Push Service 是否已经被停止。
@@ -110,7 +130,7 @@ window.JPush.isPushStopped(function (result) {
```
## 开启 Debug 模式
### API - setDebugMode
### setDebugMode
用于开启 Debug 模式,显示更多的日志信息。
#### 代码示例
@@ -120,11 +140,13 @@ window.JPush.setDebugMode(true)
```
#### 参数说明
- isOpen: true开启 Debug 模式false关闭 Debug 模式,不显示错误信息之外的日志信息。
- true: 开启 Debug 模式;
- false: 关闭 Debug 模式,不显示错误信息之外的日志信息。
## 获取 RegistrationID
### API - getRegistrationID
### getRegistrationID
RegistrationID 定义:
@@ -378,7 +400,7 @@ window.JPush.checkTagBindState({ sequence: 1, tag: 'tag1' },
### event - jpush.openNotification
点击通知进入应用程序时会出发改事件
点击通知进入应用程序时触发
#### 代码示例
@@ -395,8 +417,6 @@ document.addEventListener("jpush.openNotification", function (event) {
}, false)
```
> ps点击通知后传递的 json object 保存在 window.JPush.openNotification直接访问即可字段示例根据实际推送情况可能略有差别请注意。
- Android:
```json
@@ -435,7 +455,7 @@ document.addEventListener("jpush.openNotification", function (event) {
### event - jpush.receiveNotification
收到通知时触发该事件
收到通知时触发。
#### 代码示例
@@ -453,8 +473,6 @@ document.addEventListener("jpush.receiveNotification", function (event) {
}, false)
```
> ps点击通知后传递的 json object 保存在 window.JPush.receiveNotification直接访问即可字段示例根据实际推送情况可能略有差别请注意。
- Android:
```json
@@ -493,7 +511,7 @@ document.addEventListener("jpush.receiveNotification", function (event) {
### event - jpush.receiveMessage
收到自定义消息时触发这个事件,推荐使用事件的方式传递。
收到自定义消息时触发,推荐使用事件的方式传递。
但同时保留了 `receiveMessageIniOSCallback` 的回调函数,兼容以前的代码。
@@ -512,8 +530,6 @@ document.addEventListener("jpush.receiveMessage", function (event) {
}, false)
```
> ps点击通知后传递的 json object 保存在 window.JPush.receiveMessage直接访问即可字段示例根据实际推送情况可能略有差别请注意。
- Android:
```json

View File

@@ -143,7 +143,7 @@ window.JPush.getRegistrationID(function(data) {
#### event - jpush.openNotification
点击通知启动或唤醒应用程序时会发该事件
点击通知(包括 localNotification 和 remoteNotification启动或唤醒应用程序时会发该事件
#### 代码示例
@@ -379,7 +379,7 @@ window.JPush.addLocalNotificationForIOS(delayTime, content, badge, notificationI
#### 参数说明
- delayTime: 本地推送延迟多长时间后显示,数值类型或纯数字的字符型均可。
- delayTime: 本地推送延迟多长时间后显示,数值类型或纯数字的字符型均可,单位为秒
- content: 本地推送需要显示的内容。
- badge: 角标的数字。如果不需要改变角标传-1。数值类型或纯数字的字符型均可。
- notificationID: 本地推送标识符,字符串。
@@ -433,6 +433,34 @@ window.JPush.clearAllLocalNotifications()
监听 `jpush.receiveLocalNotification` 事件获取「App 在后台时点击通知横幅」或「App 在前台时收到」均会触发该事件。
#### 代码示例
- 在你需要接收通知的的 js 文件中加入:
```js
document.addEventListener("jpush.receiveLocalNotification", onLocalNotification, false)
```
- onLocalNotification 需要这样写:
```js
var onLocalNotification = function(event) {
alert("receive Local Notification:" + JSON.stringify(event))
}
```
- event 举例
```json
{
badge = 1;
content = "Hello JPush";
extras = {
"__JPUSHNotificationKey" = notificationIdentify_1;
};
}
```
### iOS 10 收到本地通知
监听 [jpush.receiveNotification](#前台收到推送)、[jpush.openNotification](点击推送通知),获取推送内容后,通过获取到的 `__JPUSHNotificationKey` 字段([本地通知](#本地通知) 设置的 `notificationID`)来判断是本地通知,并处理。

View File

@@ -9,7 +9,13 @@
<script type="text/javascript" src="js/jquery.mobile-1.1.1.js"></script>
<script type="text/javascript" src="cordova.js"></script>
<script type="text/javascript">
var onDeviceReady = function() {
document.addEventListener("jpush.receiveRegistrationId", function (event) {
alert("receiveRegistrationId" + JSON.stringify(event));
$("#registrationId").html(event.registrationId);
}, false)
initiateUI();
};
@@ -88,13 +94,11 @@
var initiateUI = function() {
try {
window.JPush.init();
window.JPush.setDebugMode(true);
window.setTimeout(getRegistrationID, 1000);
if (device.platform != "Android") {
window.JPush.setDebugModeFromIos();
window.JPush.setApplicationIconBadgeNumber(0);
} else {
window.JPush.setDebugMode(true);
window.JPush.setStatisticsOpen(true);
}
} catch (exception) {
console.log(exception);
@@ -118,9 +122,9 @@
}
window.JPush.setTags({ sequence: 1, tags: tags },
(result) => {
function (result) {
$("#tagsResult").html(result.tags)
}, (error) => {
}, function (error) {
alert(error.code)
})
} catch (exception) {
@@ -130,19 +134,19 @@
$("#getAllTags").click(function (event) {
window.JPush.getAllTags({ sequence: 2 },
(result) => {
function (result) {
$("#tagsResult").html(result.tags)
}, (error) => {
}, function (error) {
alert(error.code)
})
})
$("#cleanTags").click(function (event) {
window.JPush.cleanTags({ sequence: 2 },
(result) => {
function (result) {
alert(result.sequence)
$("#tagsResult").html("")
}, (error) => {
}, function (error) {
alert(error.code)
})
})
@@ -150,27 +154,27 @@
$("#setAlias").click(function (event) {
var alias = $("#aliasText").val()
window.JPush.setAlias({ sequence: 1, alias: alias },
(result) => {
function (result) {
$("#aliasResult").html(result.alias)
}, (error) => {
}, function (error){
alert(error.code)
})
})
$("#getAlias").click(function (event) {
window.JPush.getAlias({ sequence: 2 },
(result) => {
function (result) {
alert(JSON.stringify(result));
}, (error) => {
}, function (error) {
alert(error.code)
})
});
$("#deleteAlias").click(function (event) {
window.JPush.deleteAlias({ sequence: 3 },
(result) => {
function (result) {
alert(JSON.stringify(result));
}, (error) => {
}, function (error) {
alert(error.code)
})
});

BIN
example/js/.DS_Store vendored

Binary file not shown.

View File

@@ -0,0 +1,25 @@
import { Component } from '@angular/core';
import { Platform } from 'ionic-angular';
import { StatusBar } from '@ionic-native/status-bar';
import { SplashScreen } from '@ionic-native/splash-screen';
import { JPush } from '@jiguang-ionic/jpush';
import { HomePage } from '../pages/home/home';
@Component({
templateUrl: 'app.html'
})
export class MyApp {
rootPage:any = HomePage;
constructor(platform: Platform, statusBar: StatusBar, splashScreen: SplashScreen, jpush: JPush) {
platform.ready().then(() => {
// Okay, so the platform is ready and our plugins are available.
// Here you can do any higher level native things you might need.
statusBar.styleDefault();
splashScreen.hide();
jpush.init();
jpush.setDebugMode(true);
});
}
}

View File

@@ -0,0 +1 @@
<ion-nav [root]="rootPage"></ion-nav>

View File

@@ -0,0 +1,34 @@
import { BrowserModule } from '@angular/platform-browser';
import { ErrorHandler, NgModule } from '@angular/core';
import { IonicApp, IonicErrorHandler, IonicModule } from 'ionic-angular';
import { SplashScreen } from '@ionic-native/splash-screen';
import { StatusBar } from '@ionic-native/status-bar';
import { Device } from '@ionic-native/device';
import { JPush } from '@jiguang-ionic/jpush';
import { MyApp } from './app.component';
import { HomePage } from '../pages/home/home';
@NgModule({
declarations: [
MyApp,
HomePage
],
imports: [
BrowserModule,
IonicModule.forRoot(MyApp)
],
bootstrap: [IonicApp],
entryComponents: [
MyApp,
HomePage
],
providers: [
StatusBar,
SplashScreen,
Device,
JPush,
{provide: ErrorHandler, useClass: IonicErrorHandler}
]
})
export class AppModule {}

View File

@@ -0,0 +1,36 @@
<ion-header>
<ion-navbar>
<ion-title>
JPush Ionic Example
</ion-title>
</ion-navbar>
</ion-header>
<ion-content padding>
<ion-list>
<ion-item>
<div>Registration Id: {{registrationId}}</div>
<button ion-button full (click)="getRegistrationID()">Get Registration Id</button>
</ion-item>
<ion-item>
<button ion-button full (click)="setTags()">Set tags - Tag1, Tag2</button>
<button ion-button full (click)="addTags()">Add tags - Tag3, Tag4</button>
<button ion-button full (click)="checkTagBindState()">Check tag bind state - Tag1</button>
<button ion-button full (click)="deleteTags()">Delete tags - Tag4</button>
<button ion-button full (click)="getAllTags()">Get all tags</button>
<button ion-button full (click)="cleanTags()">Clean tags</button>
</ion-item>
<ion-item>
<button ion-button full (click)="setAlias()">Set Alias - TestAlias</button>
<button ion-button full (click)="getAlias()">Get Alias</button>
<button ion-button full (click)="deleteAlias()">Delete Alias</button>
</ion-item>
<ion-item>
<button ion-button full (click)="addLocalNotification()">Trigger local notification after 5 seconds</button>
</ion-item>
</ion-list>
</ion-content>

View File

@@ -0,0 +1,3 @@
page-home {
}

View File

@@ -0,0 +1,146 @@
import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
import { JPush } from '@jiguang-ionic/jpush';
import { Device } from '@ionic-native/device';
@Component({
selector: 'page-home',
templateUrl: 'home.html'
})
export class HomePage {
public registrationId: string;
devicePlatform: string;
sequence: number = 0;
tagResultHandler = function(result) {
var sequence: number = result.sequence;
var tags: Array<string> = result.tags == null ? [] : result.tags;
alert('Success!' + '\nSequence: ' + sequence + '\nTags: ' + tags.toString());
};
aliasResultHandler = function(result) {
var sequence: number = result.sequence;
var alias: string = result.alias;
alert('Success!' + '\nSequence: ' + sequence + '\nAlias: ' + alias);
};
errorHandler = function(err) {
var sequence: number = err.sequence;
var code = err.code;
alert('Error!' + '\nSequence: ' + sequence + '\nCode: ' + code);
};
constructor(public navCtrl: NavController, public jpush: JPush, device: Device) {
this.devicePlatform = device.platform;
document.addEventListener('jpush.receiveNotification', (event: any) => {
var content;
if (this.devicePlatform == 'Android') {
content = event.alert;
} else {
content = event.aps.alert;
}
alert('Receive notification: ' + JSON.stringify(event));
}, false);
document.addEventListener('jpush.openNotification', (event: any) => {
var content;
if (this.devicePlatform == 'Android') {
content = event.alert;
} else { // iOS
if (event.aps == undefined) { // 本地通知
content = event.content;
} else { // APNS
content = event.aps.alert;
}
}
alert('open notification: ' + JSON.stringify(event));
}, false);
document.addEventListener('jpush.receiveLocalNotification', (event: any) => {
// iOS(*,9) Only , iOS(10,*) 将在 jpush.openNotification 和 jpush.receiveNotification 中触发。
var content;
if (this.devicePlatform == 'Android') {
} else {
content = event.content;
}
alert('receive local notification: ' + JSON.stringify(event));
}, false);
}
getRegistrationID() {
this.jpush.getRegistrationID()
.then(rId => {
this.registrationId = rId;
});
}
setTags() {
this.jpush.setTags({ sequence: this.sequence++, tags: ['Tag1', 'Tag2']})
.then(this.tagResultHandler)
.catch(this.errorHandler);
}
addTags() {
this.jpush.addTags({ sequence: this.sequence++, tags: ['Tag3', 'Tag4']})
.then(this.tagResultHandler)
.catch(this.errorHandler);
}
checkTagBindState() {
this.jpush.checkTagBindState({ sequence: this.sequence++, tag: 'Tag1' })
.then(result => {
var sequence = result.sequence;
var tag = result.tag;
var isBind = result.isBind;
alert('Sequence: ' + sequence + '\nTag: ' + tag + '\nIsBind: ' + isBind);
}).catch(this.errorHandler);
}
deleteTags() {
this.jpush.deleteTags({ sequence: this.sequence++, tags: ['Tag4']})
.then(this.tagResultHandler)
.catch(this.errorHandler);
}
getAllTags() {
this.jpush.getAllTags({ sequence: this.sequence++ })
.then(this.tagResultHandler)
.catch(this.errorHandler);
}
cleanTags() {
this.jpush.cleanTags({ sequence: this.sequence++ })
.then(this.tagResultHandler)
.catch(this.errorHandler);
}
setAlias() {
this.jpush.setAlias({ sequence: this.sequence++, alias: 'TestAlias' })
.then(this.aliasResultHandler)
.catch(this.errorHandler);
}
getAlias() {
this.jpush.getAlias({ sequence: this.sequence++ })
.then(this.aliasResultHandler)
.catch(this.errorHandler);
}
deleteAlias() {
this.jpush.deleteAlias({ sequence: this.sequence++ })
.then(this.aliasResultHandler)
.catch(this.errorHandler);
}
addLocalNotification() {
if (this.devicePlatform == 'Android') {
this.jpush.addLocalNotification(0, 'Hello JPush', 'JPush', 1, 5000);
} else {
this.jpush.addLocalNotificationForIOS(5, 'Hello JPush', 1, 'localNoti1');
}
}
}

171
ionic/index.ts Normal file
View File

@@ -0,0 +1,171 @@
import { Plugin, Cordova, IonicNativePlugin } from '@ionic-native/core';
import { Injectable } from '@angular/core';
export interface TagOptions {
sequence: number;
tags?: Array<string>;
}
export interface AliasOptions {
sequence: number;
alias?: string;
}
@Plugin({
pluginName: 'JPush',
plugin: 'jpush-phonegap-plugin',
pluginRef: 'plugins.jPushPlugin',
repo: 'https://github.com/jpush/jpush-phonegap-plugin',
install: 'ionic cordova plugin add jpush-phonegap-plugin --variable APP_KEY=your_app_key',
installVariables: ['APP_KEY'],
platforms: ['Android', 'iOS']
})
@Injectable()
export class JPush extends IonicNativePlugin {
@Cordova()
init(): Promise<any> { return; }
@Cordova()
setDebugMode(enable: boolean): Promise<any> { return; }
@Cordova()
getRegistrationID(): Promise<any> { return; }
@Cordova()
stopPush(): Promise<any> { return; }
@Cordova()
resumePush(): Promise<any> { return; }
@Cordova()
isPushStopped(): Promise<any> { return; }
@Cordova()
setTags(params: TagOptions): Promise<any> { return; }
@Cordova()
addTags(params: TagOptions): Promise<any> { return; }
@Cordova()
deleteTags(params: TagOptions): Promise<any> { return; }
@Cordova()
cleanTags(params: TagOptions): Promise<any> { return; }
@Cordova()
getAllTags(params: TagOptions): Promise<any> { return; }
/**
* @param params { sequence: number, tag: string }
*/
@Cordova()
checkTagBindState(params: object): Promise<any> { return; }
@Cordova()
setAlias(params: AliasOptions): Promise<any> { return; }
@Cordova()
deleteAlias(params: AliasOptions): Promise<any> { return; }
@Cordova()
getAlias(params: AliasOptions): Promise<any> { return; }
/**
* Determinate whether the application notification has been opened.
*
* iOS: 0: closed; >1: opened.
* UIRemoteNotificationTypeNone = 0,
* UIRemoteNotificationTypeBadge = 1 << 0,
* UIRemoteNotificationTypeSound = 1 << 1,
* UIRemoteNotificationTypeAlert = 1 << 2,
* UIRemoteNotificationTypeNewsstandContentAvailability = 1 << 3
*
* Android: 0: closed; 1: opened.
*/
@Cordova()
getUserNotificationSettings(): Promise<any> { return; }
@Cordova()
clearLocalNotifications(): Promise<any> { return; }
// iOS API - start
@Cordova()
setBadge(badge: number): Promise<any> { return; }
@Cordova()
resetBadge(): Promise<any> { return; }
@Cordova()
setApplicationIconBadgeNumber(badge: number): Promise<any> { return; }
@Cordova()
getApplicationIconBadgeNumber(): Promise<any> { return; }
@Cordova()
addLocalNotificationForIOS(delayTime: number, content: string, badge: number, identifierKey: string, extras?: object): Promise<any> { return; }
@Cordova()
deleteLocalNotificationWithIdentifierKeyInIOS(identifierKey: string): Promise<any> { return; }
@Cordova()
addDismissActions(actions: Array<object>, categoryId: string): Promise<any> { return; }
@Cordova()
addNotificationActions(actions: Array<object>, categoryId: string): Promise<any> { return; }
@Cordova()
setLocation(latitude: number, longitude: number): Promise<any> { return; }
@Cordova()
startLogPageView(pageName: string): Promise<any> { return; }
@Cordova()
stopLogPageView(pageName: string): Promise<any> { return; }
@Cordova()
beginLogPageView(pageName: string, duration: number): Promise<any> { return; }
// iOS API - end
// Android API - start
@Cordova()
getConnectionState(): Promise<any> { return; }
@Cordova()
setBasicPushNotificationBuilder(): Promise<any> { return; }
@Cordova()
setCustomPushNotificationBuilder(): Promise<any> { return; }
@Cordova()
clearAllNotification(): Promise<any> { return; }
@Cordova()
clearNotificationById(id: number): Promise<any> { return; }
@Cordova()
setLatestNotificationNum(num: number): Promise<any> { return; }
@Cordova()
addLocalNotification(builderId: number, content: string, title: string, notificationId: number, broadcastTime: number, extras?: string): Promise<any> { return; }
@Cordova()
removeLocalNotification(notificationId: number): Promise<any> { return; }
@Cordova()
reportNotificationOpened(msgId: number): Promise<any> { return; }
@Cordova()
requestPermission(): Promise<any> { return; }
@Cordova()
setSilenceTime(startHour: number, startMinute: number, endHour: number, endMinute: number): Promise<any> { return; }
@Cordova()
setPushTime(weekdays: Array<string>, startHour: number, endHour: number): Promise<any> { return; }
// Android API - end
}

67
ionic/jpush/index.d.ts vendored Normal file
View File

@@ -0,0 +1,67 @@
import { IonicNativePlugin } from '@ionic-native/core';
export interface TagOptions {
sequence: number;
tags?: Array<string>;
}
export interface AliasOptions {
sequence: number;
alias?: string;
}
export declare class JPush extends IonicNativePlugin {
init(): Promise<any>;
setDebugMode(enable: boolean): Promise<any>;
getRegistrationID(): Promise<any>;
stopPush(): Promise<any>;
resumePush(): Promise<any>;
isPushStopped(): Promise<any>;
setTags(params: TagOptions): Promise<any>;
addTags(params: TagOptions): Promise<any>;
deleteTags(params: TagOptions): Promise<any>;
cleanTags(params: TagOptions): Promise<any>;
getAllTags(params: TagOptions): Promise<any>;
/**
* @param params { sequence: number, tag: string }
*/
checkTagBindState(params: object): Promise<any>;
setAlias(params: AliasOptions): Promise<any>;
deleteAlias(params: AliasOptions): Promise<any>;
getAlias(params: AliasOptions): Promise<any>;
/**
* Determinate whether the application notification has been opened.
*
* iOS: 0: closed; >1: opened.
* UIRemoteNotificationTypeNone = 0,
* UIRemoteNotificationTypeBadge = 1 << 0,
* UIRemoteNotificationTypeSound = 1 << 1,
* UIRemoteNotificationTypeAlert = 1 << 2,
* UIRemoteNotificationTypeNewsstandContentAvailability = 1 << 3
*
* Android: 0: closed; 1: opened.
*/
getUserNotificationSettings(): Promise<any>;
clearLocalNotifications(): Promise<any>;
setBadge(badge: number): Promise<any>;
resetBadge(): Promise<any>;
setApplicationIconBadgeNumber(badge: number): Promise<any>;
getApplicationIconBadgeNumber(): Promise<any>;
addLocalNotificationForIOS(delayTime: number, content: string, badge: number, identifierKey: string, extras?: object): Promise<any>;
deleteLocalNotificationWithIdentifierKeyInIOS(identifierKey: string): Promise<any>;
addDismissActions(actions: Array<object>, categoryId: string): Promise<any>;
addNotificationActions(actions: Array<object>, categoryId: string): Promise<any>;
setLocation(latitude: number, longitude: number): Promise<any>;
startLogPageView(pageName: string): Promise<any>;
stopLogPageView(pageName: string): Promise<any>;
beginLogPageView(pageName: string, duration: number): Promise<any>;
getConnectionState(): Promise<any>;
setBasicPushNotificationBuilder(): Promise<any>;
setCustomPushNotificationBuilder(): Promise<any>;
clearAllNotification(): Promise<any>;
clearNotificationById(id: number): Promise<any>;
setLatestNotificationNum(num: number): Promise<any>;
addLocalNotification(builderId: number, content: string, title: string, notificationId: number, broadcastTime: number, extras?: string): Promise<any>;
removeLocalNotification(notificationId: number): Promise<any>;
reportNotificationOpened(msgId: number): Promise<any>;
requestPermission(): Promise<any>;
setSilenceTime(startHour: number, startMinute: number, endHour: number, endMinute: number): Promise<any>;
setPushTime(weekdays: Array<string>, startHour: number, endHour: number): Promise<any>;
}

352
ionic/jpush/index.js Normal file
View File

@@ -0,0 +1,352 @@
var __extends = (this && this.__extends) || (function () {
var extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
import { Plugin, Cordova, IonicNativePlugin } from '@ionic-native/core';
import { Injectable } from '@angular/core';
var JPush = (function (_super) {
__extends(JPush, _super);
function JPush() {
return _super !== null && _super.apply(this, arguments) || this;
}
JPush.prototype.init = function () { return; };
JPush.prototype.setDebugMode = function (enable) { return; };
JPush.prototype.getRegistrationID = function () { return; };
JPush.prototype.stopPush = function () { return; };
JPush.prototype.resumePush = function () { return; };
JPush.prototype.isPushStopped = function () { return; };
JPush.prototype.setTags = function (params) { return; };
JPush.prototype.addTags = function (params) { return; };
JPush.prototype.deleteTags = function (params) { return; };
JPush.prototype.cleanTags = function (params) { return; };
JPush.prototype.getAllTags = function (params) { return; };
/**
* @param params { sequence: number, tag: string }
*/
JPush.prototype.checkTagBindState = function (params) { return; };
JPush.prototype.setAlias = function (params) { return; };
JPush.prototype.deleteAlias = function (params) { return; };
JPush.prototype.getAlias = function (params) { return; };
/**
* Determinate whether the application notification has been opened.
*
* iOS: 0: closed; >1: opened.
* UIRemoteNotificationTypeNone = 0,
* UIRemoteNotificationTypeBadge = 1 << 0,
* UIRemoteNotificationTypeSound = 1 << 1,
* UIRemoteNotificationTypeAlert = 1 << 2,
* UIRemoteNotificationTypeNewsstandContentAvailability = 1 << 3
*
* Android: 0: closed; 1: opened.
*/
JPush.prototype.getUserNotificationSettings = function () { return; };
JPush.prototype.clearLocalNotifications = function () { return; };
// iOS API - start
JPush.prototype.setBadge = function (badge) { return; };
JPush.prototype.resetBadge = function () { return; };
JPush.prototype.setApplicationIconBadgeNumber = function (badge) { return; };
JPush.prototype.getApplicationIconBadgeNumber = function () { return; };
JPush.prototype.addLocalNotificationForIOS = function (delayTime, content, badge, identifierKey, extras) { return; };
JPush.prototype.deleteLocalNotificationWithIdentifierKeyInIOS = function (identifierKey) { return; };
JPush.prototype.addDismissActions = function (actions, categoryId) { return; };
JPush.prototype.addNotificationActions = function (actions, categoryId) { return; };
JPush.prototype.setLocation = function (latitude, longitude) { return; };
JPush.prototype.startLogPageView = function (pageName) { return; };
JPush.prototype.stopLogPageView = function (pageName) { return; };
JPush.prototype.beginLogPageView = function (pageName, duration) { return; };
// iOS API - end
// Android API - start
JPush.prototype.getConnectionState = function () { return; };
JPush.prototype.setBasicPushNotificationBuilder = function () { return; };
JPush.prototype.setCustomPushNotificationBuilder = function () { return; };
JPush.prototype.clearAllNotification = function () { return; };
JPush.prototype.clearNotificationById = function (id) { return; };
JPush.prototype.setLatestNotificationNum = function (num) { return; };
JPush.prototype.addLocalNotification = function (builderId, content, title, notificationId, broadcastTime, extras) { return; };
JPush.prototype.removeLocalNotification = function (notificationId) { return; };
JPush.prototype.reportNotificationOpened = function (msgId) { return; };
JPush.prototype.requestPermission = function () { return; };
JPush.prototype.setSilenceTime = function (startHour, startMinute, endHour, endMinute) { return; };
JPush.prototype.setPushTime = function (weekdays, startHour, endHour) { return; };
// Android API - end
JPush.decorators = [
{ type: Injectable },
];
/** @nocollapse */
JPush.ctorParameters = function () { return []; };
__decorate([
Cordova(),
__metadata("design:type", Function),
__metadata("design:paramtypes", []),
__metadata("design:returntype", Promise)
], JPush.prototype, "init", null);
__decorate([
Cordova(),
__metadata("design:type", Function),
__metadata("design:paramtypes", [Boolean]),
__metadata("design:returntype", Promise)
], JPush.prototype, "setDebugMode", null);
__decorate([
Cordova(),
__metadata("design:type", Function),
__metadata("design:paramtypes", []),
__metadata("design:returntype", Promise)
], JPush.prototype, "getRegistrationID", null);
__decorate([
Cordova(),
__metadata("design:type", Function),
__metadata("design:paramtypes", []),
__metadata("design:returntype", Promise)
], JPush.prototype, "stopPush", null);
__decorate([
Cordova(),
__metadata("design:type", Function),
__metadata("design:paramtypes", []),
__metadata("design:returntype", Promise)
], JPush.prototype, "resumePush", null);
__decorate([
Cordova(),
__metadata("design:type", Function),
__metadata("design:paramtypes", []),
__metadata("design:returntype", Promise)
], JPush.prototype, "isPushStopped", null);
__decorate([
Cordova(),
__metadata("design:type", Function),
__metadata("design:paramtypes", [Object]),
__metadata("design:returntype", Promise)
], JPush.prototype, "setTags", null);
__decorate([
Cordova(),
__metadata("design:type", Function),
__metadata("design:paramtypes", [Object]),
__metadata("design:returntype", Promise)
], JPush.prototype, "addTags", null);
__decorate([
Cordova(),
__metadata("design:type", Function),
__metadata("design:paramtypes", [Object]),
__metadata("design:returntype", Promise)
], JPush.prototype, "deleteTags", null);
__decorate([
Cordova(),
__metadata("design:type", Function),
__metadata("design:paramtypes", [Object]),
__metadata("design:returntype", Promise)
], JPush.prototype, "cleanTags", null);
__decorate([
Cordova(),
__metadata("design:type", Function),
__metadata("design:paramtypes", [Object]),
__metadata("design:returntype", Promise)
], JPush.prototype, "getAllTags", null);
__decorate([
Cordova(),
__metadata("design:type", Function),
__metadata("design:paramtypes", [Object]),
__metadata("design:returntype", Promise)
], JPush.prototype, "checkTagBindState", null);
__decorate([
Cordova(),
__metadata("design:type", Function),
__metadata("design:paramtypes", [Object]),
__metadata("design:returntype", Promise)
], JPush.prototype, "setAlias", null);
__decorate([
Cordova(),
__metadata("design:type", Function),
__metadata("design:paramtypes", [Object]),
__metadata("design:returntype", Promise)
], JPush.prototype, "deleteAlias", null);
__decorate([
Cordova(),
__metadata("design:type", Function),
__metadata("design:paramtypes", [Object]),
__metadata("design:returntype", Promise)
], JPush.prototype, "getAlias", null);
__decorate([
Cordova(),
__metadata("design:type", Function),
__metadata("design:paramtypes", []),
__metadata("design:returntype", Promise)
], JPush.prototype, "getUserNotificationSettings", null);
__decorate([
Cordova(),
__metadata("design:type", Function),
__metadata("design:paramtypes", []),
__metadata("design:returntype", Promise)
], JPush.prototype, "clearLocalNotifications", null);
__decorate([
Cordova(),
__metadata("design:type", Function),
__metadata("design:paramtypes", [Number]),
__metadata("design:returntype", Promise)
], JPush.prototype, "setBadge", null);
__decorate([
Cordova(),
__metadata("design:type", Function),
__metadata("design:paramtypes", []),
__metadata("design:returntype", Promise)
], JPush.prototype, "resetBadge", null);
__decorate([
Cordova(),
__metadata("design:type", Function),
__metadata("design:paramtypes", [Number]),
__metadata("design:returntype", Promise)
], JPush.prototype, "setApplicationIconBadgeNumber", null);
__decorate([
Cordova(),
__metadata("design:type", Function),
__metadata("design:paramtypes", []),
__metadata("design:returntype", Promise)
], JPush.prototype, "getApplicationIconBadgeNumber", null);
__decorate([
Cordova(),
__metadata("design:type", Function),
__metadata("design:paramtypes", [Number, String, Number, String, Object]),
__metadata("design:returntype", Promise)
], JPush.prototype, "addLocalNotificationForIOS", null);
__decorate([
Cordova(),
__metadata("design:type", Function),
__metadata("design:paramtypes", [String]),
__metadata("design:returntype", Promise)
], JPush.prototype, "deleteLocalNotificationWithIdentifierKeyInIOS", null);
__decorate([
Cordova(),
__metadata("design:type", Function),
__metadata("design:paramtypes", [Array, String]),
__metadata("design:returntype", Promise)
], JPush.prototype, "addDismissActions", null);
__decorate([
Cordova(),
__metadata("design:type", Function),
__metadata("design:paramtypes", [Array, String]),
__metadata("design:returntype", Promise)
], JPush.prototype, "addNotificationActions", null);
__decorate([
Cordova(),
__metadata("design:type", Function),
__metadata("design:paramtypes", [Number, Number]),
__metadata("design:returntype", Promise)
], JPush.prototype, "setLocation", null);
__decorate([
Cordova(),
__metadata("design:type", Function),
__metadata("design:paramtypes", [String]),
__metadata("design:returntype", Promise)
], JPush.prototype, "startLogPageView", null);
__decorate([
Cordova(),
__metadata("design:type", Function),
__metadata("design:paramtypes", [String]),
__metadata("design:returntype", Promise)
], JPush.prototype, "stopLogPageView", null);
__decorate([
Cordova(),
__metadata("design:type", Function),
__metadata("design:paramtypes", [String, Number]),
__metadata("design:returntype", Promise)
], JPush.prototype, "beginLogPageView", null);
__decorate([
Cordova(),
__metadata("design:type", Function),
__metadata("design:paramtypes", []),
__metadata("design:returntype", Promise)
], JPush.prototype, "getConnectionState", null);
__decorate([
Cordova(),
__metadata("design:type", Function),
__metadata("design:paramtypes", []),
__metadata("design:returntype", Promise)
], JPush.prototype, "setBasicPushNotificationBuilder", null);
__decorate([
Cordova(),
__metadata("design:type", Function),
__metadata("design:paramtypes", []),
__metadata("design:returntype", Promise)
], JPush.prototype, "setCustomPushNotificationBuilder", null);
__decorate([
Cordova(),
__metadata("design:type", Function),
__metadata("design:paramtypes", []),
__metadata("design:returntype", Promise)
], JPush.prototype, "clearAllNotification", null);
__decorate([
Cordova(),
__metadata("design:type", Function),
__metadata("design:paramtypes", [Number]),
__metadata("design:returntype", Promise)
], JPush.prototype, "clearNotificationById", null);
__decorate([
Cordova(),
__metadata("design:type", Function),
__metadata("design:paramtypes", [Number]),
__metadata("design:returntype", Promise)
], JPush.prototype, "setLatestNotificationNum", null);
__decorate([
Cordova(),
__metadata("design:type", Function),
__metadata("design:paramtypes", [Number, String, String, Number, Number, String]),
__metadata("design:returntype", Promise)
], JPush.prototype, "addLocalNotification", null);
__decorate([
Cordova(),
__metadata("design:type", Function),
__metadata("design:paramtypes", [Number]),
__metadata("design:returntype", Promise)
], JPush.prototype, "removeLocalNotification", null);
__decorate([
Cordova(),
__metadata("design:type", Function),
__metadata("design:paramtypes", [Number]),
__metadata("design:returntype", Promise)
], JPush.prototype, "reportNotificationOpened", null);
__decorate([
Cordova(),
__metadata("design:type", Function),
__metadata("design:paramtypes", []),
__metadata("design:returntype", Promise)
], JPush.prototype, "requestPermission", null);
__decorate([
Cordova(),
__metadata("design:type", Function),
__metadata("design:paramtypes", [Number, Number, Number, Number]),
__metadata("design:returntype", Promise)
], JPush.prototype, "setSilenceTime", null);
__decorate([
Cordova(),
__metadata("design:type", Function),
__metadata("design:paramtypes", [Array, Number, Number]),
__metadata("design:returntype", Promise)
], JPush.prototype, "setPushTime", null);
JPush = __decorate([
Plugin({
pluginName: 'JPush',
plugin: 'jpush-phonegap-plugin',
pluginRef: 'plugins.jPushPlugin',
repo: 'https://github.com/jpush/jpush-phonegap-plugin',
install: 'ionic cordova plugin add jpush-phonegap-plugin --variable APP_KEY=your_app_key',
installVariables: ['APP_KEY'],
platforms: ['Android', 'iOS']
})
], JPush);
return JPush;
}(IonicNativePlugin));
export { JPush };
//# sourceMappingURL=index.js.map

1
ionic/jpush/index.js.map Normal file

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

18
ionic/jpush/package.json Normal file
View File

@@ -0,0 +1,18 @@
{
"name": "@jiguang-ionic/jpush",
"version": "1.0.2",
"description": "JPush support for ionic-native",
"module": "index.js",
"typings": "index.d.ts",
"author": "hevin",
"license": "MIT",
"peerDependencies": {
"@ionic-native/core": "^4.2.0",
"@angular/core": "*",
"rxjs": "^5.0.1"
},
"repository": {
"type": "git",
"url": "https://github.com/jpush/jpush-phonegap-plugin"
}
}

View File

@@ -1,6 +1,6 @@
{
"name": "jpush-phonegap-plugin",
"version": "3.2.8",
"version": "3.2.13",
"description": "JPush for cordova plugin",
"cordova": {
"id": "jpush-phonegap-plugin",

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.8">
version="3.2.13">
<name>JPush</name>
<description>JPush for cordova plugin</description>
@@ -207,7 +207,7 @@
<meta-data android:name="JPUSH_APPKEY" android:value="$APP_KEY" />
</config-file>
<source-file src="src/android/libs/jpush-android-3.0.9.jar" target-dir="libs" />
<source-file src="src/android/libs/jpush-android-3.1.0.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" />

View File

@@ -96,6 +96,7 @@ public class JPushEventReceiver extends JPushMessageReceiver {
} catch (JSONException e) {
e.printStackTrace();
}
callback.success(resultJson);
} else {
try {
@@ -103,7 +104,6 @@ public class JPushEventReceiver extends JPushMessageReceiver {
} catch (JSONException e) {
e.printStackTrace();
}
callback.error(resultJson);
}

Binary file not shown.

View File

@@ -28,25 +28,24 @@
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:[[self jpushFormatAPNSDic: notification.userInfo[UIApplicationLaunchOptionsRemoteNotificationKey]] toJsonString]];
}
if ([notification.userInfo valueForKey:UIApplicationLaunchOptionsLocalNotificationKey]) {
@@ -56,7 +55,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]];
}
}
@@ -84,6 +83,23 @@ NSDictionary *_launchOptions;
[JPushPlugin fireDocumentEvent:JPushDocumentEvent_receiveRegistrationId jsString:[event toJsonString]];
}
- (NSMutableDictionary *)jpushFormatAPNSDic:(NSDictionary *)dic {
NSMutableDictionary *extras = @{}.mutableCopy;
for (NSString *key in dic) {
if([key isEqualToString:@"_j_business"] ||
[key isEqualToString:@"_j_msgid"] ||
[key isEqualToString:@"_j_uid"] ||
[key isEqualToString:@"actionIdentifier"] ||
[key isEqualToString:@"aps"]) {
continue;
}
extras[key] = dic[key];
}
NSMutableDictionary *formatDic = dic.mutableCopy;
formatDic[@"extras"] = extras;
return formatDic;
}
-(void)registerForRemoteNotification{
if ([[UIDevice currentDevice].systemVersion floatValue] >= 10.0) {
#ifdef NSFoundationVersionNumber_iOS_9_x_Max
@@ -132,26 +148,48 @@ NSDictionary *_launchOptions;
default:
break;
}
[JPushPlugin fireDocumentEvent:eventName jsString:[userInfo toJsonString]];
[JPushPlugin fireDocumentEvent:eventName jsString:[[self jpushFormatAPNSDic:userInfo] toJsonString]];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(30 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
completionHandler(UIBackgroundFetchResultNewData);
});
}
-(void)jpushNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(NSInteger))completionHandler{
NSMutableDictionary *userInfo = [NSMutableDictionary dictionaryWithDictionary:notification.request.content.userInfo];
[JPushPlugin fireDocumentEvent:JPushDocumentEvent_ReceiveNotification jsString:[userInfo toJsonString]];
completionHandler(UNNotificationPresentationOptionBadge|UNNotificationPresentationOptionSound|UNNotificationPresentationOptionAlert);
NSMutableDictionary *userInfo = @[].mutableCopy;
if ([notification.request.trigger isKindOfClass:[UNPushNotificationTrigger class]]) {
userInfo = [self jpushFormatAPNSDic:notification.request.content.userInfo];
} else {
UNNotificationContent *content = notification.request.content;
userInfo = [NSMutableDictionary dictionaryWithDictionary:@{@"content": content.body,
@"badge": content.badge,
@"extras": content.userInfo
}];
userInfo[@"identifier"] = notification.request.identifier;
}
[JPushPlugin fireDocumentEvent:JPushDocumentEvent_ReceiveNotification jsString:[userInfo toJsonString]];
completionHandler(UNNotificationPresentationOptionBadge|UNNotificationPresentationOptionSound|UNNotificationPresentationOptionAlert);
}
-(void)jpushNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)())completionHandler{
NSMutableDictionary *userInfo = [NSMutableDictionary dictionaryWithDictionary:response.notification.request.content.userInfo];
@try {
[userInfo setValue:[response valueForKey:@"userText"] forKey:@"userText"];
} @catch (NSException *exception) { }
[userInfo setValue:response.actionIdentifier forKey:@"actionIdentifier"];
[JPushPlugin fireDocumentEvent:JPushDocumentEvent_OpenNotification jsString:[userInfo toJsonString]];
completionHandler();
UNNotification *notification = response.notification;
NSMutableDictionary *userInfo = nil;
if ([notification.request.trigger isKindOfClass:[UNPushNotificationTrigger class]]) {
userInfo = [self jpushFormatAPNSDic:notification.request.content.userInfo];
} else {
UNNotificationContent *content = notification.request.content;
userInfo = [NSMutableDictionary dictionaryWithDictionary:@{@"content": content.body,
@"badge": content.badge,
@"extras": content.userInfo
}];
userInfo[@"identifier"] = notification.request.identifier;
}
[JPushPlugin fireDocumentEvent:JPushDocumentEvent_OpenNotification jsString:[userInfo toJsonString]];
completionHandler();
}
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification {

View File

@@ -1,100 +1,102 @@
//
// PushTalkPlugin.h
// PushTalk
//
// Created by zhangqinghe on 13-12-13.
//
//
#import <Cordova/CDV.h>
@interface JPushPlugin : CDVPlugin{
}
//注册通知服务并启动 SDK
-(void)startJPushSDK:(CDVInvokedUrlCommand*)command;
//以下为js中可调用接口
//设置标签、别名
-(void)setTags:(CDVInvokedUrlCommand*)command;
-(void)addTags:(CDVInvokedUrlCommand*)command;
-(void)deleteTags:(CDVInvokedUrlCommand*)command;
-(void)cleanTags:(CDVInvokedUrlCommand*)command;
-(void)getAllTags:(CDVInvokedUrlCommand*)command;
-(void)checkTagBindState:(CDVInvokedUrlCommand*)command;
-(void)setAlias:(CDVInvokedUrlCommand*)command;
-(void)deleteAlias:(CDVInvokedUrlCommand*)command;
-(void)getAlias:(CDVInvokedUrlCommand*)command;
//获取 RegistrationID
-(void)getRegistrationID:(CDVInvokedUrlCommand*)command;
//页面统计
-(void)startLogPageView:(CDVInvokedUrlCommand*)command;
-(void)stopLogPageView:(CDVInvokedUrlCommand*)command;
-(void)beginLogPageView:(CDVInvokedUrlCommand*)command;
//设置角标到服务器,服务器下一次发消息时,会设置成这个值
//本接口不会改变应用本地的角标值.
-(void)setBadge:(CDVInvokedUrlCommand*)command;
//相当于 [setBadge:0]
-(void)resetBadge:(CDVInvokedUrlCommand*)command;
//应用本地的角标值设置/获取
-(void)setApplicationIconBadgeNumber:(CDVInvokedUrlCommand*)command;
-(void)getApplicationIconBadgeNumber:(CDVInvokedUrlCommand*)command;
//停止与恢复推送
-(void)stopPush:(CDVInvokedUrlCommand*)command;
-(void)resumePush:(CDVInvokedUrlCommand*)command;
-(void)isPushStopped:(CDVInvokedUrlCommand*)command;
//开关日志
-(void)setDebugModeFromIos:(CDVInvokedUrlCommand*)command;
-(void)setLogOFF:(CDVInvokedUrlCommand*)command;
-(void)crashLogON:(CDVInvokedUrlCommand*)command;
//本地推送
-(void)setLocalNotification:(CDVInvokedUrlCommand*)command;
-(void)deleteLocalNotificationWithIdentifierKey:(CDVInvokedUrlCommand*)command;
-(void)clearAllLocalNotifications:(CDVInvokedUrlCommand*)command;
//地理位置上报 [latitude,longitude]
-(void)setLocation:(CDVInvokedUrlCommand*)command;
//检查用户的推送设置情况
-(void)getUserNotificationSettings:(CDVInvokedUrlCommand*)command;
//ios 10 APIs
-(void)addDismissActions:(CDVInvokedUrlCommand*)command;
-(void)addNotificationActions:(CDVInvokedUrlCommand*)command;
/*
* 以下为js中可监听到的事件
* jpush.openNotification 点击推送消息启动或唤醒app
* jpush.receiveMessage 收到自定义消息
* jpush.receiveNotification 前台收到推送
* jpush.backgroundNotification 后台收到推送
*/
# pragma mark - private
+(void)fireDocumentEvent:(NSString*)eventName jsString:(NSString*)jsString;
+(void)setupJPushSDK:(NSDictionary*)userInfo;
@end
JPushPlugin *SharedJPushPlugin;
@interface NSDictionary (JPush)
-(NSString*)toJsonString;
@end
@interface NSString (JPush)
-(NSDictionary*)toDictionary;
@end
//
// PushTalkPlugin.h
// PushTalk
//
// Created by zhangqinghe on 13-12-13.
//
//
#import <Cordova/CDV.h>
static NSMutableDictionary *_jpushEventCache;
@interface JPushPlugin : CDVPlugin{
}
//注册通知服务并启动 SDK
-(void)startJPushSDK:(CDVInvokedUrlCommand*)command;
//以下为js中可调用接口
//设置标签、别名
-(void)setTags:(CDVInvokedUrlCommand*)command;
-(void)addTags:(CDVInvokedUrlCommand*)command;
-(void)deleteTags:(CDVInvokedUrlCommand*)command;
-(void)cleanTags:(CDVInvokedUrlCommand*)command;
-(void)getAllTags:(CDVInvokedUrlCommand*)command;
-(void)checkTagBindState:(CDVInvokedUrlCommand*)command;
-(void)setAlias:(CDVInvokedUrlCommand*)command;
-(void)deleteAlias:(CDVInvokedUrlCommand*)command;
-(void)getAlias:(CDVInvokedUrlCommand*)command;
//获取 RegistrationID
-(void)getRegistrationID:(CDVInvokedUrlCommand*)command;
//页面统计
-(void)startLogPageView:(CDVInvokedUrlCommand*)command;
-(void)stopLogPageView:(CDVInvokedUrlCommand*)command;
-(void)beginLogPageView:(CDVInvokedUrlCommand*)command;
//设置角标到服务器,服务器下一次发消息时,会设置成这个值
//本接口不会改变应用本地的角标值.
-(void)setBadge:(CDVInvokedUrlCommand*)command;
//相当于 [setBadge:0]
-(void)resetBadge:(CDVInvokedUrlCommand*)command;
//应用本地的角标值设置/获取
-(void)setApplicationIconBadgeNumber:(CDVInvokedUrlCommand*)command;
-(void)getApplicationIconBadgeNumber:(CDVInvokedUrlCommand*)command;
//停止与恢复推送
-(void)stopPush:(CDVInvokedUrlCommand*)command;
-(void)resumePush:(CDVInvokedUrlCommand*)command;
-(void)isPushStopped:(CDVInvokedUrlCommand*)command;
//开关日志
-(void)setDebugModeFromIos:(CDVInvokedUrlCommand*)command;
-(void)setLogOFF:(CDVInvokedUrlCommand*)command;
-(void)crashLogON:(CDVInvokedUrlCommand*)command;
//本地推送
-(void)setLocalNotification:(CDVInvokedUrlCommand*)command;
-(void)deleteLocalNotificationWithIdentifierKey:(CDVInvokedUrlCommand*)command;
-(void)clearAllLocalNotifications:(CDVInvokedUrlCommand*)command;
//地理位置上报 [latitude,longitude]
-(void)setLocation:(CDVInvokedUrlCommand*)command;
//检查用户的推送设置情况
-(void)getUserNotificationSettings:(CDVInvokedUrlCommand*)command;
//ios 10 APIs
-(void)addDismissActions:(CDVInvokedUrlCommand*)command;
-(void)addNotificationActions:(CDVInvokedUrlCommand*)command;
/*
* 以下为js中可监听到的事件
* jpush.openNotification 点击推送消息启动或唤醒app
* jpush.receiveMessage 收到自定义消息
* jpush.receiveNotification 前台收到推送
* jpush.backgroundNotification 后台收到推送
*/
# pragma mark - private
+(void)fireDocumentEvent:(NSString*)eventName jsString:(NSString*)jsString;
+(void)setupJPushSDK:(NSDictionary*)userInfo;
@end
static JPushPlugin *SharedJPushPlugin;
@interface NSDictionary (JPush)
-(NSString*)toJsonString;
@end
@interface NSString (JPush)
-(NSDictionary*)toDictionary;
@end

View File

@@ -83,12 +83,35 @@
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 {
@@ -218,7 +241,7 @@
CDVPluginResult* result;
if (iResCode == 0) {
[dic setObject:[iTags allObjects] forKey:@"tags"];
dic[@"tag"] = tag;
[dic setObject:[NSNumber numberWithBool:isBind] forKey:@"isBind"];
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:dic];
} else {