Compare commits

...

53 Commits

Author SHA1 Message Date
Hevin 3101dcdd8e Merge remote-tracking branch 'refs/remotes/origin/dev' 2016-07-20 14:41:42 +08:00
Hevin a46da92fa1 Format js file. 2016-07-20 14:40:40 +08:00
Hevin 5547d5716e Update event callback. 2016-07-20 14:34:35 +08:00
Hevin 7da0a25db0 Format js. 2016-07-19 17:15:40 +08:00
Hevin 0c74ff328d Merge remote-tracking branch 'refs/remotes/origin/master' into dev 2016-07-19 17:13:58 +08:00
Hevin 2065ad44ce Format README. 2016-07-18 16:39:15 +08:00
Hevin cbe8e511f2 Update README 2016-07-18 16:06:14 +08:00
Hevin 9a47c88873 Merge remote-tracking branch 'refs/remotes/origin/dev' 2016-07-16 00:17:25 +08:00
Hevin 684039b044 Format README 2016-07-15 18:02:02 +08:00
Hevin 356de48d31 Format README 2016-07-15 18:00:39 +08:00
Hevin d412b10d3e Update README 2016-07-15 17:56:39 +08:00
Hevin 44345d9753 Merge remote-tracking branch 'refs/remotes/origin/dev' 2016-07-13 23:08:30 +08:00
Hevin 5f93fc3f49 Update API to don't depend support lib. 2016-07-13 23:07:01 +08:00
Hevin 673a402c51 Merge remote-tracking branch 'refs/remotes/origin/master' into dev 2016-07-13 22:23:37 +08:00
Hevin 09e0d62360 Update README 2016-07-13 22:03:35 +08:00
Hevin b4830d4ef7 Remove dependency. 2016-07-13 16:34:40 +08:00
Hevin 2c3bf53792 Update npm version. 2016-07-12 14:57:58 +08:00
Hevin 78ebe0e787 Update plugin id. 2016-07-12 14:51:20 +08:00
Hevin 54f87adde2 Add API doc. 2016-07-12 14:09:48 +08:00
Hevin c101552938 Merge remote-tracking branch 'refs/remotes/origin/dev' 2016-07-12 13:54:29 +08:00
Hevin c918efb99a Update version number. 2016-07-12 13:53:12 +08:00
Hevin 9be760e65e Add API doc. 2016-07-12 13:47:19 +08:00
Hevin cea1eb85fa Add Android API. 2016-07-12 13:34:08 +08:00
E.B f8c56b5aa1 iOS - update API
1.更新检查用户通知设置 API 的参数
2016-07-12 11:52:47 +08:00
E.B 0bb6838477 iOS - update new API
1.添加检测用户通知设置的 API
2016-07-12 11:16:58 +08:00
Hevin c6b8a6f2f6 Update Plugin.xml. 2016-07-11 10:03:09 +08:00
Hevin 42fbe62d19 Merge branch 'dev' of https://github.com/jpush/jpush-phonegap-plugin into dev 2016-07-10 17:08:49 +08:00
Hevin d3ea41f513 Merge remote-tracking branch 'refs/remotes/origin/master' into dev 2016-07-10 17:05:53 +08:00
Hevin 5ff7d14bec Update Plugin name. 2016-07-10 17:05:05 +08:00
Hevin 1c41e96f42 Update README. 2016-07-08 13:26:39 +08:00
Hevin 48adf59ec8 Update README. 2016-07-07 17:54:48 +08:00
E.B 3369072687 iOS - update SDK 2.1.8
1.更新 iOS SDK 2.1.8
2016-07-01 10:34:49 +08:00
Hevin 8e7e957884 Merge remote-tracking branch 'refs/remotes/origin/dev' 2016-06-28 16:00:04 +08:00
Hevin c615f8255e Optimize installition & update Android SDK to 2.1.7 2016-06-28 15:57:34 +08:00
E.B 7ffec241fa iOS - fix #151
1. fix #151
2016-06-27 10:59:26 +08:00
Hevin de32f4a057 Format README 2016-06-27 10:40:03 +08:00
Hevin 1cd7ecf3e5 Merge remote-tracking branch 'refs/remotes/origin/dev' 2016-06-27 10:37:39 +08:00
Hevin b01b4bf259 Add dependency & Update README 2016-06-27 10:34:16 +08:00
Hevin f8efb4f010 Merge remote-tracking branch 'refs/remotes/origin/master' into dev 2016-06-27 10:29:39 +08:00
Hevin 870fc12c0d Merge remote-tracking branch 'refs/remotes/origin/dev' 2016-06-23 13:23:13 +08:00
Hevin dc2cdda00c Update README
Add QQ group badge.
2016-06-23 13:18:27 +08:00
Hevin 1c96487869 Update install script. 2016-06-17 17:44:42 +08:00
Hevin 8d24ce7c48 Merge remote-tracking branch 'refs/remotes/origin/dev' 2016-06-17 13:41:20 +08:00
Hevin 280846779d Update Android SDK to 2.1.5 2016-06-17 13:39:23 +08:00
Hevin 1ba048ee1b Update README 2016-06-12 16:25:11 +08:00
E.B e4500dd513 iOS - update
1.拼写错误
2016-05-31 13:36:43 +08:00
Hevin a511072101 Merge remote-tracking branch 'refs/remotes/origin/dev' 2016-05-30 18:01:17 +08:00
Hevin 851ff1f23b Update version. 2016-05-30 18:00:47 +08:00
Hevin 5cf5bd39d1 Merge remote-tracking branch 'refs/remotes/origin/master' into dev 2016-05-30 17:58:41 +08:00
E.B 07bb05f337 Merge branch 'dev' 2016-05-30 17:34:32 +08:00
E.B ceeb2fc7cf iOS - fix #147
1.fix #147
2016-05-30 17:29:07 +08:00
E.B 1eccd58059 Merge branch 'dev' 2016-05-27 13:58:45 +08:00
Hevin be6dbf4fe6 Merge remote-tracking branch 'refs/remotes/origin/dev' 2016-05-25 16:15:02 +08:00
26 changed files with 549 additions and 553 deletions
+36 -77
View File
@@ -1,76 +1,40 @@
# 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)
[![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/jpush/jpush-phonegap-plugin) [![QQ Group](https://img.shields.io/badge/QQ%20Group-413602425-red.svg)]()
[![release](https://img.shields.io/badge/release-2.1.5-blue.svg)](https://github.com/jpush/jpush-phonegap-plugin/releases) [![release](https://img.shields.io/badge/release-2.2.4-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)
支持 iOS, Android 的 Cordova 推送插件。 支持 iOS, Android 的 Cordova 推送插件。
> 如需要 IM 功能的插件,可关注 [JMessage PhoneGap Plugin](https://github.com/jpush/jmessage-phonegap-plugin)。
## 功能特性 > 如需要短信验证码功能的插件,可关注 [JSMS Cordova Plugin](https://github.com/jpush/cordova-plugin-jsms)。
+ 发送推送通知。
+ 发送推送自定义消息。
+ 设置推送标签和别名。
+ 设置角标(iOS)。
*如需要 IM 功能插件,请关注 [jmessage-phonegap-plugin](https://github.com/jpush/jmessage-phonegap-plugin)* > QQ 交流群:413602425
## 安装 ## 集成步骤
### 准备工作
1. cordova create 文件夹名字 包名 应用名字 - 先安装 cordova-plugin-device 插件:
cordova create Myproj com.myproj.jpush MyTestProj
2. 添加平台:
cd Myproj
cordova platform add android
cordova platform add ios
ps: 这里请注意iOS平台,必须先执行 cordova platform add ios,
然后再执行 cordova plugin add xxxxx 命令,不然有一些必须要的链接库需要手动添加。
### 集成步骤(Android & iOS)
#### 1.首先安装 cordova device 插件
cordova plugin add cordova-plugin-device cordova plugin add cordova-plugin-device
#### 2.安装 JPush PhoneGap Plugin - 安装本插件
安装 JPush PhoneGap Plugin 有两种方法 - 通过 Cordova Plugins 安装,要求 Cordova CLI 5.0+
方法一:在线安装
通过 cordova plugins 安装,要求 phonegap/cordova CLI 5.0+:
cordova plugin add jpush-phonegap-plugin --variable API_KEY=your_jpush_appkey cordova plugin add jpush-phonegap-plugin --variable API_KEY=your_jpush_appkey
直接通过 url 安装: - 或者直接通过 url 安装
cordova plugin add https://github.com/jpush/jpush-phonegap-plugin.git --variable API_KEY=your_jpush_appkey cordova plugin add https://github.com/jpush/jpush-phonegap-plugin.git --variable API_KEY=your_jpush_appkey
方法二:下载到本地安装 -下载到本地安装
使用 git 命令将 JPush PhoneGap 插件下载的本地,目录标记为 $JPUSH_PLUGIN_DIR。 cordova plugin add Your_Plugin_Path --variable API_KEY=your_jpush_appkey
git clone https://github.com/jpush/jpush-phonegap-plugin.git
cordova plugin add $JPUSH_PLUGIN_DIR --variable API_KEY=your_jpush_appkey
[Android 手动安装文档地址](/doc/Android_handle_install.md)
[IOS 手动安装文档地址](/doc/iOS_install.md)
#### 3.在 js 中调用函数,初始化 JPush
//由于 PhoneGap 插件采用了 Lazy load 的特性,所以建议在 js 文件能执行的最开始就添加
window.plugins.jPushPlugin.init();
## Demo ## Demo
插件中包含示例 Demo。若想参考,可以在 $JPUSH_PLUGIN_DIR/example 文件夹内找到并拷贝以下文件: 插件项目中包含一个简单的 Demo。若想参考,可以在 */example* 文件夹内找到并拷贝以下文件:
src/example/index.html -> www/index.html src/example/index.html -> www/index.html
src/example/css/* -> www/css src/example/css/* -> www/css
@@ -78,57 +42,52 @@
## 关于 PhoneGap build 云服务 ## 关于 PhoneGap build 云服务
该项目基于 cordova 实现,目前无法使用 PhoneGap build 云服务进行打包,建议使用本地环境进行打包。 该项目基于 Cordova 实现,目前无法使用 PhoneGap build 云服务进行打包,建议使用本地环境进行打包。
## API 说明 ## API 说明
插件的 API 集中在 JPushPlugin.js 文件中,该文件的具体位置如下: 插件的 API 在 JPushPlugin.js 文件中,该文件的具体位置如下:
### Android
Android:
[Project]/assets/www/plugins/cn.jpush.phonegap.JPushPlugin/www [Project]/assets/www/plugins/cn.jpush.phonegap.JPushPlugin/www
iOS: ### iOS
[Project]/www/plugins/cn.jpush.phonegap.JPushPlugin/www [Project]/www/plugins/cn.jpush.phonegap.JPushPlugin/www
### 具体的 API 请参考: ### 具体的 API 请参考:
- [公共 API](/doc/Common_detail_api.md) - [公共 API](/doc/Common_detail_api.md)
- [iOS API](/doc/iOS_API.md) - [iOS API](/doc/iOS_API.md)
- [Android API](/doc/Android_detail_api.md) - [Android API](/doc/Android_detail_api.md)
## 常见问题 ## 常见问题
若要使用 CLI 来编译项目,注意使用 cordova compile 而不是 cordova build,因为 cordova build 会清除对插件文件的修改。 若要使用 CLI 来编译项目,注意使用 cordova compile 而不是 cordova build 命令,因为如果修改了插件安装时默认写入到 AndroidManifest.xml
具体 cordova CLI 用法可参考[cordova CLI 官方文档](https://cordova.apache.org/docs/en/latest/reference/cordova-cli/index.html) 中的代码,cordova build 可能会导致对 AndroidManifest.xml 的修改
Cordova CLI 的具体用法可参考 [Cordova CLI 官方文档](https://cordova.apache.org/docs/en/latest/reference/cordova-cli/index.html)。
### 1. Android ### Android
eclipse 中 import PhoneGap 工程之后出现:`Type CallbackContext cannot be resolved to a type` - Eclipse 中 import PhoneGap 工程之后出现:*Type CallbackContext cannot be resolved to a type*
解决方案:eclipse 中右键单击工程名,Build Path -> Config Build Path -> Projects -> 选中工程名称 -> CordovaLib -> 点击 add。 解决方案:Eclipse 中右键单击工程名,Build Path -> Config Build Path -> Projects -> 选中工程名称 -> CordovaLib -> 点击 add。
### 2. iOS ### iOS
- 收不到推送:
请首先按照正确方式再次配置证书、描述文件
[iOS 证书设置指南](http://docs.jpush.io/client/ios_tutorials/#ios_1)
- 设置 PushConfig.plist - 设置 PushConfig.plist
- APP_KEY:应用标识。
- CHANNEL:渠道标识。
- IsProduction:是否生产环境。
- IsIDFA:是否使用 IDFA 启动 SDK。
- APP_KEY:应用标识
- CHANNEL:渠道标识
- IsProduction:是否生产环境
- IsIDFA:是否使用 IDFA 启动 sdk
- 收不到推送:
请首先按照正确方式再次配置证书、描述文件,具体可参考 [iOS 证书设置指南](http://docs.jpush.io/client/ios_tutorials/#ios_1)。
## 更多 ## 更多
[JPush 官网文档](http://docs.jpush.io/) - QQ 群:413602425
- [JPush 官网文档](http://docs.jpush.io/)
如有问题可访问[极光社区](http://community.jpush.cn/) - 如有问题可访问[极光社区](http://community.jiguang.cn/)
+29 -4
View File
@@ -6,7 +6,7 @@
- [获取点击通知内容](#获取点击通知内容) - [获取点击通知内容](#获取点击通知内容)
- [获取通知内容](#获取通知内容) - [获取通知内容](#获取通知内容)
- [获取自定义消息推送内容](#获取自定义消息推送内容) - [获取自定义消息推送内容](#获取自定义消息推送内容)
- [判断系统设置中是否允许当前应用推送](#判断系统设置中是否允许当前应用推送)
## 停止与恢复推送服务 ## 停止与恢复推送服务
### API - init ### API - init
@@ -226,7 +226,7 @@ JPush SDK 会以广播的形式发送 RegistrationID 到应用程序。
var alertContent; var alertContent;
if(device.platform == "Android") { if(device.platform == "Android") {
alertContent = window.plugins.jPushPlugin.openNotification.alert; alertContent = event.alert;
} else { } else {
alertContent = event.aps.alert; alertContent = event.aps.alert;
} }
@@ -280,7 +280,7 @@ ps:点击通知后传递的 json object 保存在 window.plugins.jPushPlugin.o
var alertContent; var alertContent;
if(device.platform == "Android") { if(device.platform == "Android") {
alertContent = window.plugins.jPushPlugin.receiveNotification.alert; alertContent = event.alert;
} else { } else {
alertContent = event.aps.alert; alertContent = event.aps.alert;
} }
@@ -339,7 +339,7 @@ ps:点击通知后传递的 json object 保存在 window.plugins.jPushPlugin.r
try{ try{
var message var message
if(device.platform == "Android") { if(device.platform == "Android") {
message = window.plugins.jPushPlugin.receiveMessage.message; message = event.message;
} else { } else {
message = event.content; message = event.content;
} }
@@ -370,3 +370,28 @@ ps:点击通知后传递的 json object 保存在 window.plugins.jPushPlugin.r
"content":"今天去哪儿", "content":"今天去哪儿",
"extras":{"key":"不填写没有"} "extras":{"key":"不填写没有"}
} }
## 判断系统设置中是否允许当前应用推送
### API - getUserNotificationSettings
判断系统设置中是否允许当前应用推送。
在 Android 中,返回值为 0 时,代表系统设置中关闭了推送;为 1 时,代表打开了推送(目前仅适用于Android 4.4+)。
在 iOS 中,返回值为 0 时,代表系统设置中关闭了推送;大于 0 时,代表打开了推送,且能够根据返回值判断具体通知形式:
UIRemoteNotificationTypeNone = 0, // 0
UIRemoteNotificationTypeBadge = 1 << 0, // 1
UIRemoteNotificationTypeSound = 1 << 1, // 2
UIRemoteNotificationTypeAlert = 1 << 2, // 4
UIRemoteNotificationTypeNewsstandContentAvailability = 1 << 3 // 8
#### 代码示例
window.plugins.jPushPlugin.getUserNotificationSettings(function(result) {
if(result == 0) {
// 系统设置中已关闭应用推送。
} else if(result > 0) {
// 系统设置中打开了应用推送。
}
});
+5 -5
View File
@@ -57,7 +57,7 @@ JPush SDK 会恢复正常的默认行为。(因为保存在本地的状态数
### API - isPushStopped ### API - isPushStopped
iOS平台,检查推送服务是否注册 iOS平台,检查推送服务是否停止
#### 接口定义 #### 接口定义
@@ -69,12 +69,12 @@ iOS平台,检查推送服务是否注册。
- callback 回调函数,用来通知 JPush 的推送服务是否开启。 - callback 回调函数,用来通知 JPush 的推送服务是否开启。
#### 代码示例 #### 代码示例
window.plugins.jPushPlugin.resumePush(callback) window.plugins.jPushPlugin.isPushStopped(callback)
var onCallback = function(data) { var callback = function(data) {
if(data > 0) { if(data > 0) {
// 开启 // 已关闭
} else { } else {
// 关闭 // 已开启
} }
} }
BIN
View File
Binary file not shown.
+3 -3
View File
@@ -47,7 +47,7 @@
try { try {
var alertContent; var alertContent;
if (device.platform == "Android") { if (device.platform == "Android") {
alertContent = window.plugins.jPushPlugin.openNotification.alert; alertContent = event.alert;
} else { } else {
alertContent = event.aps.alert; alertContent = event.aps.alert;
} }
@@ -61,7 +61,7 @@
try { try {
var alertContent; var alertContent;
if (device.platform == "Android") { if (device.platform == "Android") {
alertContent = window.plugins.jPushPlugin.receiveNotification.alert; alertContent = event.alert;
} else { } else {
alertContent = event.aps.alert; alertContent = event.aps.alert;
} }
@@ -75,7 +75,7 @@
try { try {
var message; var message;
if (device.platform == "Android") { if (device.platform == "Android") {
message = window.plugins.jPushPlugin.receiveMessage.message; message = event.message;
} else { } else {
message = event.content; message = event.content;
} }
+3 -2
View File
@@ -1,9 +1,9 @@
{ {
"name": "jpush-phonegap-plugin", "name": "jpush-phonegap-plugin",
"version": "2.1.7", "version": "2.2.5",
"description": "JPush for cordova plugin", "description": "JPush for cordova plugin",
"cordova": { "cordova": {
"id": "cn.jpush.phonegap.JPushPlugin", "id": "jpush-phonegap-plugin",
"platforms": [ "platforms": [
"ios", "ios",
"android" "android"
@@ -16,6 +16,7 @@
"keywords": [ "keywords": [
"JPush", "JPush",
"push", "push",
"Push",
"ecosystem:cordova", "ecosystem:cordova",
"cordova-ios", "cordova-ios",
"cordova-android" "cordova-android"
+27 -38
View File
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<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="cn.jpush.phonegap.JPushPlugin" id="jpush-phonegap-plugin"
version="2.1.7"> version="2.2.4">
<name>JPush Plugin</name> <name>JPush Plugin</name>
<description>JPush for cordova plugin</description> <description>JPush for cordova plugin</description>
@@ -17,7 +17,7 @@
</engines> </engines>
<js-module src="www/JPushPlugin.js" name="JPushPlugin"> <js-module src="www/JPushPlugin.js" name="JPushPlugin">
<clobbers target="jPushPlugin"/> <clobbers target="JPush" />
</js-module> </js-module>
<platform name="ios"> <platform name="ios">
@@ -31,7 +31,7 @@
<source-file src="src/ios/Plugins/JPushPlugin.m" /> <source-file src="src/ios/Plugins/JPushPlugin.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-2.1.6.a" framework="true" /> <source-file src="src/ios/lib/jpush-ios-2.1.8.a" framework="true" />
<header-file src="src/ios/Plugins/AppDelegate+JPush.h" /> <header-file src="src/ios/Plugins/AppDelegate+JPush.h" />
<source-file src="src/ios/Plugins/AppDelegate+JPush.m" /> <source-file src="src/ios/Plugins/AppDelegate+JPush.m" />
<resource-file src="src/ios/PushConfig.plist" /> <resource-file src="src/ios/PushConfig.plist" />
@@ -51,13 +51,7 @@
</config-file> </config-file>
</platform> </platform>
<!-- android -->
<platform name="android"> <platform name="android">
<hook type="after_plugin_add" src="scripts/android-install.js" />
<hook type="after_plugin_install" src="scripts/android-install.js" />
<hook type="before_plugin_rm" src="scripts/android-install.js" />
<hook type="before_plugin_uninstall" src="scripts/android-install.js" />
<config-file target="res/xml/config.xml" parent="/*"> <config-file target="res/xml/config.xml" parent="/*">
<feature name="JPushPlugin"> <feature name="JPushPlugin">
<param name="android-package" value="cn.jpush.phonegap.JPushPlugin" /> <param name="android-package" value="cn.jpush.phonegap.JPushPlugin" />
@@ -78,16 +72,11 @@
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" /> <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
<uses-permission android:name="android.permission.WRITE_SETTINGS" /> <uses-permission android:name="android.permission.WRITE_SETTINGS" />
<permission <permission android:name="$PACKAGE_NAME.permission.JPUSH_MESSAGE" android:protectionLevel="signature" />
android:name="$PACKAGE_NAME.permission.JPUSH_MESSAGE"
android:protectionLevel="signature"/>
</config-file> </config-file>
<config-file target="AndroidManifest.xml" parent="/manifest/application"> <config-file target="AndroidManifest.xml" parent="/manifest/application">
<!-- Required SDK核心功能--> <!-- Required SDK核心功能-->
<activity <activity android:name="cn.jpush.android.ui.PushActivity" android:theme="@android:style/Theme.Translucent.NoTitleBar" android:configChanges="orientation|keyboardHidden">
android:name="cn.jpush.android.ui.PushActivity"
android:theme="@android:style/Theme.Translucent.NoTitleBar"
android:configChanges="orientation|keyboardHidden">
<intent-filter> <intent-filter>
<action android:name="cn.jpush.android.ui.PushActivity" /> <action android:name="cn.jpush.android.ui.PushActivity" />
<category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.DEFAULT" />
@@ -96,22 +85,17 @@
</activity> </activity>
<!-- Rich push 核心功能 since 2.0.6--> <!-- Rich push 核心功能 since 2.0.6-->
<activity <activity android:name="cn.jpush.android.ui.PopWinActivity" android:theme="@style/MyDialogStyle" android:exported="false">
android:name="cn.jpush.android.ui.PopWinActivity"
android:theme="@style/MyDialogStyle"
android:exported="false">
</activity> </activity>
<!-- Required SDK核心功能--> <!-- Required SDK核心功能-->
<service <service android:name="cn.jpush.android.service.DownloadService"
android:name="cn.jpush.android.service.DownloadService"
android:enabled="true" android:enabled="true"
android:exported="false"> android:exported="false">
</service> </service>
<!-- Required SDK 核心功能--> <!-- Required SDK 核心功能-->
<service <service android:name="cn.jpush.android.service.PushService"
android:name="cn.jpush.android.service.PushService"
android:enabled="true" android:enabled="true"
android:exported="false"> android:exported="false">
<intent-filter> <intent-filter>
@@ -123,8 +107,7 @@
</service> </service>
<!-- Required SDK核心功能--> <!-- Required SDK核心功能-->
<receiver <receiver android:name="cn.jpush.android.service.PushReceiver"
android:name="cn.jpush.android.service.PushReceiver"
android:enabled="true"> android:enabled="true">
<intent-filter android:priority="1000"> <intent-filter android:priority="1000">
<action android:name="cn.jpush.android.intent.NOTIFICATION_RECEIVED_PROXY" /> <action android:name="cn.jpush.android.intent.NOTIFICATION_RECEIVED_PROXY" />
@@ -139,14 +122,20 @@
<intent-filter> <intent-filter>
<action android:name="android.intent.action.PACKAGE_ADDED" /> <action android:name="android.intent.action.PACKAGE_ADDED" />
<action android:name="android.intent.action.PACKAGE_REMOVED" /> <action android:name="android.intent.action.PACKAGE_REMOVED" />
<data android:scheme="package"/>
</intent-filter> </intent-filter>
</receiver> </receiver>
<!-- since 1.8.0 option 可选项。用于同一设备中不同应用的JPush服务相互拉起的功能。 -->
<!-- 若不启用该功能可删除该组件,将不拉起其他应用也不能被其他应用拉起 -->
<service android:name="cn.jpush.android.service.DaemonService" android:enabled="true" android:exported="true">
<intent-filter>
<action android:name="cn.jpush.android.intent.DaemonService" />
<category android:name="$PACKAGE_NAME" />
</intent-filter>
</service>
<!-- User defined. For test only 用户自定义的广播接收器 --> <!-- User defined. For test only 用户自定义的广播接收器 -->
<receiver <receiver android:name="cn.jpush.phonegap.MyReceiver" android:enabled="true">
android:name="cn.jpush.phonegap.MyReceiver"
android:enabled="true">
<intent-filter android:priority="1000"> <intent-filter android:priority="1000">
<action android:name="cn.jpush.android.intent.NOTIFICATION_RECEIVED_PROXY" /> <action android:name="cn.jpush.android.intent.NOTIFICATION_RECEIVED_PROXY" />
<!-- Required 显示通知栏 --> <!-- Required 显示通知栏 -->
@@ -174,15 +163,15 @@
<meta-data android:name="JPUSH_APPKEY" android:value="$API_KEY" /> <meta-data android:name="JPUSH_APPKEY" android:value="$API_KEY" />
</config-file> </config-file>
<source-file src="src/android/jpush-android-2.1.3.jar" target-dir="libs"/> <source-file src="src/android/jpush-android-2.1.7.jar" target-dir="libs" />
<source-file src="src/android/armeabi/libjpush213.so" target-dir="libs/armeabi"/> <source-file src="src/android/armeabi/libjpush217.so" target-dir="libs/armeabi" />
<source-file src="src/android/armeabi-v7a/libjpush213.so" target-dir="libs/armeabi-v7a"/> <source-file src="src/android/armeabi-v7a/libjpush217.so" target-dir="libs/armeabi-v7a" />
<source-file src="src/android/arm64-v8a/libjpush213.so" target-dir="libs/arm64-v8a"/> <source-file src="src/android/arm64-v8a/libjpush217.so" target-dir="libs/arm64-v8a" />
<source-file src="src/android/x86/libjpush213.so" target-dir="libs/x86"/> <source-file src="src/android/x86/libjpush217.so" target-dir="libs/x86" />
<source-file src="src/android/x86_64/libjpush213.so" target-dir="libs/x86_64"/> <source-file src="src/android/x86_64/libjpush217.so" target-dir="libs/x86_64" />
<!--<source-file src="src/android/JPushPlugin.java" target-dir="src/cn/jpush/phonegap"/>-->
<source-file src="src/android/MyReceiver.java" target-dir="src/cn/jpush/phonegap" /> <source-file src="src/android/MyReceiver.java" target-dir="src/cn/jpush/phonegap" />
<source-file src="src/android/JPushPlugin.java" target-dir="src/cn/jpush/phonegap" />
<source-file src="src/android/test_notification_layout.xml" target-dir="res/layout" /> <source-file src="src/android/test_notification_layout.xml" target-dir="res/layout" />
<source-file src="src/android/jpush_notification_icon.png" target-dir="res/drawable" /> <source-file src="src/android/jpush_notification_icon.png" target-dir="res/drawable" />
-49
View File
@@ -1,49 +0,0 @@
#!/usr/bin/env node
module.exports = function (context) {
var path = context.requireCordovaModule('path'),
fs = context.requireCordovaModule('fs'),
shell = context.requireCordovaModule('shelljs'),
projectRoot = context.opts.projectRoot,
ConfigParser = context.requireCordovaModule('cordova-common/src/configparser/ConfigParser'),
config = new ConfigParser(path.join(context.opts.projectRoot, "config.xml")),
packageName = config.android_packageName() || config.packageName();
console.info("Running android-install.Hook: " + context.hook
+ ", Package: " + packageName + ", Path: " + projectRoot + ".");
if (!packageName) {
console.error("Package name could not be found!");
return ;
}
// android platform available?
if (context.opts.cordova.platforms.indexOf("android") === -1) {
console.info("Android platform has not been added.");
return ;
}
var targetDir = path.join(projectRoot, "platforms", "android", "src", "cn", "jpush", "phonegap");
targetFile = path.join(targetDir, "JPushPlugin.java");
console.log(targetDir);
if (['after_plugin_add', 'after_plugin_install', 'after_platform_add'].indexOf(context.hook) === -1) {
// remove it?
try {
fs.unlinkSync(targetFile);
} catch (err) {}
} else {
// create directory
shell.mkdir('-p', targetDir);
// sync the content
fs.readFile(path.join(context.opts.plugin.dir, 'src', 'android', 'JPushPlugin.java'),
{encoding: 'utf-8'}, function (err, data) {
if (err) {
throw err;
}
data = data.replace(/^import __PACKAGE_NAME__.R;/m, 'import ' + packageName + '.R;');
fs.writeFileSync(targetFile, data);
});
}
};
+60 -15
View File
@@ -1,12 +1,14 @@
package cn.jpush.phonegap; package cn.jpush.phonegap;
import android.annotation.TargetApi;
import android.app.Activity; import android.app.Activity;
import android.app.AppOpsManager;
import android.content.Context; import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.os.Build;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.Log; import android.util.Log;
import __PACKAGE_NAME__.R;
import org.apache.cordova.CallbackContext; import org.apache.cordova.CallbackContext;
import org.apache.cordova.CordovaInterface; import org.apache.cordova.CordovaInterface;
import org.apache.cordova.CordovaPlugin; import org.apache.cordova.CordovaPlugin;
@@ -15,6 +17,8 @@ import org.json.JSONArray;
import org.json.JSONException; import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
@@ -28,7 +32,6 @@ import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
import cn.jpush.android.api.BasicPushNotificationBuilder; import cn.jpush.android.api.BasicPushNotificationBuilder;
import cn.jpush.android.api.CustomPushNotificationBuilder;
import cn.jpush.android.api.JPushInterface; import cn.jpush.android.api.JPushInterface;
import cn.jpush.android.api.TagAliasCallback; import cn.jpush.android.api.TagAliasCallback;
import cn.jpush.android.data.JPushLocalNotification; import cn.jpush.android.data.JPushLocalNotification;
@@ -37,6 +40,7 @@ public class JPushPlugin extends CordovaPlugin {
private final static List<String> methodList = private final static List<String> methodList =
Arrays.asList( Arrays.asList(
"addLocalNotification", "addLocalNotification",
"areNotificationEnabled",
"clearAllNotification", "clearAllNotification",
"clearLocalNotifications", "clearLocalNotifications",
"clearNotificationById", "clearNotificationById",
@@ -181,7 +185,7 @@ public class JPushPlugin extends CordovaPlugin {
JSONObject jExtras = new JSONObject(); JSONObject jExtras = new JSONObject();
for (Entry<String, Object> entry : extras.entrySet()) { for (Entry<String, Object> entry : extras.entrySet()) {
if (entry.getKey().equals("cn.jpush.android.EXTRA")) { if (entry.getKey().equals("cn.jpush.android.EXTRA")) {
JSONObject jo = null; JSONObject jo;
if (TextUtils.isEmpty((String) entry.getValue())) { if (TextUtils.isEmpty((String) entry.getValue())) {
jo = new JSONObject(); jo = new JSONObject();
} else { } else {
@@ -314,6 +318,16 @@ public class JPushPlugin extends CordovaPlugin {
} }
} }
void areNotificationEnabled(JSONArray data, final CallbackContext callback) {
int isEnabled;
if (hasPermission("OP_POST_NOTIFICATION")) {
isEnabled = 1;
} else {
isEnabled = 0;
}
callback.success(isEnabled);
}
void setLatestNotificationNum(JSONArray data, CallbackContext callbackContext) { void setLatestNotificationNum(JSONArray data, CallbackContext callbackContext) {
int num = -1; int num = -1;
try { try {
@@ -438,19 +452,17 @@ public class JPushPlugin extends CordovaPlugin {
} }
} }
/**
* 自定义推送通知栏样式,需要自己实现具体代码。
* http://docs.jiguang.cn/client/android_tutorials/#_11
*/
void setCustomPushNotificationBuilder(JSONArray data, void setCustomPushNotificationBuilder(JSONArray data,
CallbackContext callbackContext) { CallbackContext callbackContext) {
CustomPushNotificationBuilder builder = new CustomPushNotificationBuilder( // CustomPushNotificationBuilder builder = new CustomPushNotificationBuilder(
this.cordova.getActivity(), R.layout.test_notification_layout, // this.cordova.getActivity(), R.layout.test_notification_layout,
R.id.icon, R.id.title, R.id.text); // R.id.icon, R.id.title, R.id.text);
builder.developerArg0 = "Custom Builder 1"; // JPushInterface.setPushNotificationBuilder(2, builder);
JPushInterface.setPushNotificationBuilder(2, builder); // JPushInterface.setDefaultPushNotificationBuilder(builder);
JSONObject obj = new JSONObject();
try {
obj.put("id", 2);
} catch (JSONException e) {
e.printStackTrace();
}
} }
void clearAllNotification(JSONArray data, CallbackContext callbackContext) { void clearAllNotification(JSONArray data, CallbackContext callbackContext) {
@@ -585,4 +597,37 @@ public class JPushPlugin extends CordovaPlugin {
} }
}; };
@TargetApi(Build.VERSION_CODES.KITKAT)
private boolean hasPermission(String appOpsServiceId) {
Context context = cordova.getActivity().getApplicationContext();
AppOpsManager mAppOps = (AppOpsManager) context.getSystemService(Context.APP_OPS_SERVICE);
ApplicationInfo appInfo = context.getApplicationInfo();
String pkg = context.getPackageName();
int uid = appInfo.uid;
Class appOpsClazz = null;
try {
appOpsClazz = Class.forName(AppOpsManager.class.getName());
Method checkOpNoThrowMethod = appOpsClazz.getMethod("checkOpNoThrow",
Integer.TYPE, Integer.TYPE, String.class);
Field opValue = appOpsClazz.getDeclaredField(appOpsServiceId);
int value = opValue.getInt(Integer.class);
Object result = checkOpNoThrowMethod.invoke(mAppOps, value, uid, pkg);
return Integer.parseInt(result.toString()) == AppOpsManager.MODE_ALLOWED;
} catch (InvocationTargetException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (NoSuchMethodException e) {
e.printStackTrace();
} catch (NoSuchFieldException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
return true;
}
} }
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+3
View File
@@ -58,6 +58,9 @@
//地理位置上报 [latitude,longitude] //地理位置上报 [latitude,longitude]
-(void)setLocation:(CDVInvokedUrlCommand*)command; -(void)setLocation:(CDVInvokedUrlCommand*)command;
//检查用户的推送设置情况
-(void)getUserNotificationSettings:(CDVInvokedUrlCommand*)command;
/* /*
* 以下为js中可监听到的事件 * 以下为js中可监听到的事件
* jpush.openNotification 点击推送消息启动或唤醒app * jpush.openNotification 点击推送消息启动或唤醒app
+23 -9
View File
@@ -16,7 +16,7 @@ static NSString *const JP_APP_CHANNEL = @"CHANNEL";
static NSString *const JP_APP_ISPRODUCTION = @"IsProduction"; static NSString *const JP_APP_ISPRODUCTION = @"IsProduction";
static NSString *const JP_APP_ISIDFA = @"IsIDFA"; static NSString *const JP_APP_ISIDFA = @"IsIDFA";
static NSString *const JPushConfigFileName = @"PushConfig"; static NSString *const JPushConfigFileName = @"PushConfig";
static NSDictionary *_luanchOptions = nil; static NSDictionary *_launchOptions = nil;
@implementation JPushPlugin @implementation JPushPlugin
@@ -52,7 +52,7 @@ static NSDictionary *_luanchOptions = nil;
}else{ }else{
result = @(1); result = @(1);
} }
[self hanleResultWithValue:result command:command]; [self handleResultWithValue:result command:command];
} }
-(void)initial:(CDVInvokedUrlCommand*)command{ -(void)initial:(CDVInvokedUrlCommand*)command{
@@ -92,8 +92,8 @@ static NSDictionary *_luanchOptions = nil;
name:kJPushPluginReceiveNotification name:kJPushPluginReceiveNotification
object:nil]; object:nil];
if (_luanchOptions) { if (_launchOptions) {
NSDictionary *userInfo = [_luanchOptions NSDictionary *userInfo = [_launchOptions
valueForKey:UIApplicationLaunchOptionsRemoteNotificationKey]; valueForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
if ([userInfo count] >0) { if ([userInfo count] >0) {
NSError *error; NSError *error;
@@ -153,7 +153,7 @@ static NSDictionary *_luanchOptions = nil;
-(void)getRegistrationID:(CDVInvokedUrlCommand*)command{ -(void)getRegistrationID:(CDVInvokedUrlCommand*)command{
NSString* registrationID = [JPUSHService registrationID]; NSString* registrationID = [JPUSHService registrationID];
NSLog(@"### getRegistrationID %@",registrationID); NSLog(@"### getRegistrationID %@",registrationID);
[self hanleResultWithValue:registrationID command:command]; [self handleResultWithValue:registrationID command:command];
} }
-(void)startLogPageView:(CDVInvokedUrlCommand*)command{ -(void)startLogPageView:(CDVInvokedUrlCommand*)command{
@@ -222,7 +222,7 @@ static NSDictionary *_luanchOptions = nil;
-(void)getApplicationIconBadgeNumber:(CDVInvokedUrlCommand *)command { -(void)getApplicationIconBadgeNumber:(CDVInvokedUrlCommand *)command {
NSInteger num = [UIApplication sharedApplication].applicationIconBadgeNumber; NSInteger num = [UIApplication sharedApplication].applicationIconBadgeNumber;
NSNumber *number = [NSNumber numberWithInteger:num]; NSNumber *number = [NSNumber numberWithInteger:num];
[self hanleResultWithValue:number command:command]; [self handleResultWithValue:number command:command];
} }
-(void)setDebugModeFromIos:(CDVInvokedUrlCommand*)command{ -(void)setDebugModeFromIos:(CDVInvokedUrlCommand*)command{
@@ -259,9 +259,23 @@ static NSDictionary *_luanchOptions = nil;
[JPUSHService setLatitude:[((NSString*)command.arguments[0]) doubleValue] longitude:[((NSString*)command.arguments[1]) doubleValue]]; [JPUSHService setLatitude:[((NSString*)command.arguments[0]) doubleValue] longitude:[((NSString*)command.arguments[1]) doubleValue]];
} }
-(void)getUserNotificationSettings:(CDVInvokedUrlCommand*)command{
if ([[UIDevice currentDevice].systemVersion floatValue] >= 8.0) {
UIUserNotificationSettings *settings = [[UIApplication sharedApplication] currentUserNotificationSettings];
UIUserNotificationType type = settings.types;
NSNumber *number = [NSNumber numberWithInteger:type];
[self handleResultWithValue:number command:command];
}else{
UIRemoteNotificationType type = [[UIApplication sharedApplication] enabledRemoteNotificationTypes];
NSNumber *number = [NSNumber numberWithInteger:type];
[self handleResultWithValue:number command:command];
}
}
#pragma mark- 内部方法 #pragma mark- 内部方法
+(void)setLaunchOptions:(NSDictionary *)theLaunchOptions{ +(void)setLaunchOptions:(NSDictionary *)theLaunchOptions{
_luanchOptions = theLaunchOptions; _launchOptions = theLaunchOptions;
[JPUSHService setDebugMode]; [JPUSHService setDebugMode];
@@ -289,7 +303,7 @@ static NSDictionary *_luanchOptions = nil;
if(isIDFA){ if(isIDFA){
advertisingId = [[[ASIdentifierManager sharedManager] advertisingIdentifier] UUIDString]; advertisingId = [[[ASIdentifierManager sharedManager] advertisingIdentifier] UUIDString];
} }
[JPUSHService setupWithOption:_luanchOptions [JPUSHService setupWithOption:_launchOptions
appKey:appkey appKey:appkey
channel:channel channel:channel
apsForProduction:[isProduction boolValue] apsForProduction:[isProduction boolValue]
@@ -298,7 +312,7 @@ static NSDictionary *_luanchOptions = nil;
} }
#pragma mark 将参数返回给js #pragma mark 将参数返回给js
-(void)hanleResultWithValue:(id)value command:(CDVInvokedUrlCommand*)command{ -(void)handleResultWithValue:(id)value command:(CDVInvokedUrlCommand*)command{
CDVPluginResult *result = nil; CDVPluginResult *result = nil;
CDVCommandStatus status = CDVCommandStatus_OK; CDVCommandStatus status = CDVCommandStatus_OK;
+1 -1
View File
@@ -9,7 +9,7 @@
* Copyright (c) 2011 ~ 2015 Shenzhen HXHG. All rights reserved. * Copyright (c) 2011 ~ 2015 Shenzhen HXHG. All rights reserved.
*/ */
#define JPUSH_VERSION_NUMBER 2.1.7 #define JPUSH_VERSION_NUMBER 2.1.8
#import <Foundation/Foundation.h> #import <Foundation/Foundation.h>
+133 -124
View File
@@ -1,7 +1,4 @@
var JPushPlugin = function () {}
var JPushPlugin = function(){
};
// private plugin function // private plugin function
@@ -9,100 +6,99 @@ JPushPlugin.prototype.receiveMessage = {}
JPushPlugin.prototype.openNotification = {} JPushPlugin.prototype.openNotification = {}
JPushPlugin.prototype.receiveNotification = {} JPushPlugin.prototype.receiveNotification = {}
JPushPlugin.prototype.isPlatformIOS = function () { JPushPlugin.prototype.isPlatformIOS = function () {
var isPlatformIOS = device.platform == "iPhone" var isPlatformIOS = device.platform == 'iPhone'
|| device.platform == "iPad" || device.platform == 'iPad'
|| device.platform == "iPod touch" || device.platform == 'iPod touch'
|| device.platform == "iOS"; || device.platform == 'iOS'
return isPlatformIOS; return isPlatformIOS
} }
JPushPlugin.prototype.error_callback = function (msg) { JPushPlugin.prototype.error_callback = function (msg) {
console.log("Javascript Callback Error: " + msg); console.log('Javascript Callback Error: ' + msg)
} }
JPushPlugin.prototype.call_native = function (name, args, callback) { JPushPlugin.prototype.call_native = function (name, args, callback) {
ret = cordova.exec(callback, this.error_callback, 'JPushPlugin', name, args); ret = cordova.exec(callback, this.error_callback, 'JPushPlugin', name, args)
return ret; return ret
} }
// public methods // public methods
JPushPlugin.prototype.init = function () { JPushPlugin.prototype.init = function () {
if (this.isPlatformIOS()) { if (this.isPlatformIOS()) {
var data = []; var data = []
this.call_native("initial", data, null); this.call_native('initial', data, null)
} else { } else {
data = []; data = []
this.call_native("init", data, null); this.call_native('init', data, null)
} }
} }
JPushPlugin.prototype.getRegistrationID = function (callback) { JPushPlugin.prototype.getRegistrationID = function (callback) {
try { try {
var data = []; var data = []
this.call_native("getRegistrationID", [data], callback); this.call_native('getRegistrationID', [data], callback)
} catch(exception) { } catch(exception) {
console.log(exception); console.log(exception)
} }
} }
JPushPlugin.prototype.stopPush = function () { JPushPlugin.prototype.stopPush = function () {
data = []; data = []
this.call_native("stopPush", data, null); this.call_native('stopPush', data, null)
} }
JPushPlugin.prototype.resumePush = function () { JPushPlugin.prototype.resumePush = function () {
data = []; data = []
this.call_native("resumePush", data, null); this.call_native('resumePush', data, null)
} }
JPushPlugin.prototype.isPushStopped = function (callback) { JPushPlugin.prototype.isPushStopped = function (callback) {
data = []; data = []
this.call_native("isPushStopped", data, callback); this.call_native('isPushStopped', data, callback)
} }
// iOS methods // iOS methods
JPushPlugin.prototype.setTagsWithAlias = function (tags, alias) { JPushPlugin.prototype.setTagsWithAlias = function (tags, alias) {
try { try {
if (tags == null) { if (tags == null) {
this.setAlias(alias); this.setAlias(alias)
return; return
} }
if (alias == null) { if (alias == null) {
this.setTags(tags); this.setTags(tags)
return; return
} }
var arrayTagWithAlias = [tags]; var arrayTagWithAlias = [tags]
arrayTagWithAlias.unshift(alias); arrayTagWithAlias.unshift(alias)
this.call_native("setTagsWithAlias", arrayTagWithAlias, null); this.call_native('setTagsWithAlias', arrayTagWithAlias, null)
} catch(exception) { } catch(exception) {
console.log(exception); console.log(exception)
} }
} }
JPushPlugin.prototype.setTags = function (tags) { JPushPlugin.prototype.setTags = function (tags) {
try { try {
this.call_native("setTags", tags, null); this.call_native('setTags', tags, null)
} catch(exception) { } catch(exception) {
console.log(exception); console.log(exception)
} }
} }
JPushPlugin.prototype.setAlias = function (alias) { JPushPlugin.prototype.setAlias = function (alias) {
try { try {
this.call_native("setAlias", [alias], null); this.call_native('setAlias', [alias], null)
} catch(exception) { } catch(exception) {
console.log(exception); console.log(exception)
} }
} }
JPushPlugin.prototype.setBadge = function (value) { JPushPlugin.prototype.setBadge = function (value) {
if (this.isPlatformIOS()) { if (this.isPlatformIOS()) {
try { try {
this.call_native("setBadge", [value], null); this.call_native('setBadge', [value], null)
} catch(exception) { } catch(exception) {
console.log(exception); console.log(exception)
} }
} }
} }
@@ -110,213 +106,226 @@ JPushPlugin.prototype.setBadge = function(value) {
JPushPlugin.prototype.resetBadge = function () { JPushPlugin.prototype.resetBadge = function () {
if (this.isPlatformIOS()) { if (this.isPlatformIOS()) {
try { try {
var data = []; var data = []
this.call_native("resetBadge", [data], null); this.call_native('resetBadge', [data], null)
} catch(exception) { } catch(exception) {
console.log(exception); console.log(exception)
} }
} }
} }
JPushPlugin.prototype.setDebugModeFromIos = function () { JPushPlugin.prototype.setDebugModeFromIos = function () {
if (this.isPlatformIOS()) { if (this.isPlatformIOS()) {
var data = []; var data = []
this.call_native("setDebugModeFromIos", [data], null); this.call_native('setDebugModeFromIos', [data], null)
} }
} }
JPushPlugin.prototype.setLogOFF = function () { JPushPlugin.prototype.setLogOFF = function () {
if (this.isPlatformIOS()) { if (this.isPlatformIOS()) {
var data = []; var data = []
this.call_native("setLogOFF", [data], null); this.call_native('setLogOFF', [data], null)
} }
} }
JPushPlugin.prototype.setCrashLogON = function () { JPushPlugin.prototype.setCrashLogON = function () {
if (this.isPlatformIOS()) { if (this.isPlatformIOS()) {
var data = []; var data = []
this.call_native("crashLogON", [data], null); this.call_native('crashLogON', [data], null)
} }
} }
JPushPlugin.prototype.addLocalNotificationForIOS = function (delayTime, content, JPushPlugin.prototype.addLocalNotificationForIOS = function (delayTime, content,
badge, notificationID, extras) { badge, notificationID, extras) {
if (this.isPlatformIOS()) { if (this.isPlatformIOS()) {
var data = [delayTime, content, badge, notificationID, extras]; var data = [delayTime, content, badge, notificationID, extras]
this.call_native("setLocalNotification", data, null); this.call_native('setLocalNotification', data, null)
} }
} }
JPushPlugin.prototype.deleteLocalNotificationWithIdentifierKeyInIOS = function ( JPushPlugin.prototype.deleteLocalNotificationWithIdentifierKeyInIOS = function (
identifierKey) { identifierKey) {
if (this.isPlatformIOS()) { if (this.isPlatformIOS()) {
var data = [identifierKey]; var data = [identifierKey]
this.call_native("deleteLocalNotificationWithIdentifierKey", data, null); this.call_native('deleteLocalNotificationWithIdentifierKey', data, null)
} }
} }
JPushPlugin.prototype.clearAllLocalNotifications = function () { JPushPlugin.prototype.clearAllLocalNotifications = function () {
if (this.isPlatformIOS()) { if (this.isPlatformIOS()) {
var data = []; var data = []
this.call_native("clearAllLocalNotifications", data, null); this.call_native('clearAllLocalNotifications', data, null)
} }
} }
JPushPlugin.prototype.setLocation = function (latitude, longitude) { JPushPlugin.prototype.setLocation = function (latitude, longitude) {
if (this.isPlatformIOS()) { if (this.isPlatformIOS()) {
var data = [latitude, longitude]; var data = [latitude, longitude]
this.call_native("setLocation", data, null); this.call_native('setLocation', data, null)
} }
} }
JPushPlugin.prototype.receiveMessageIniOSCallback = function (data) { JPushPlugin.prototype.receiveMessageIniOSCallback = function (data) {
try { try {
console.log("JPushPlugin:receiveMessageIniOSCallback--data:" + data); console.log('JPushPlugin:receiveMessageIniOSCallback--data:' + data)
var bToObj = JSON.parse(data); var bToObj = JSON.parse(data)
var content = bToObj.content; var content = bToObj.content
console.log(content); console.log(content)
} catch(exception) { } catch(exception) {
console.log("JPushPlugin:receiveMessageIniOSCallback" + exception); console.log('JPushPlugin:receiveMessageIniOSCallback' + exception)
} }
} }
JPushPlugin.prototype.startLogPageView = function (pageName) { JPushPlugin.prototype.startLogPageView = function (pageName) {
if (this.isPlatformIOS()) { if (this.isPlatformIOS()) {
this.call_native("startLogPageView", [pageName], null); this.call_native('startLogPageView', [pageName], null)
} }
} }
JPushPlugin.prototype.stopLogPageView = function (pageName) { JPushPlugin.prototype.stopLogPageView = function (pageName) {
if (this.isPlatformIOS()) { if (this.isPlatformIOS()) {
this.call_native("stopLogPageView", [pageName], null); this.call_native('stopLogPageView', [pageName], null)
} }
} }
JPushPlugin.prototype.beginLogPageView = function (pageName, duration) { JPushPlugin.prototype.beginLogPageView = function (pageName, duration) {
if (this.isPlatformIOS()) { if (this.isPlatformIOS()) {
this.call_native("beginLogPageView", [pageName, duration], null); this.call_native('beginLogPageView', [pageName, duration], null)
} }
} }
JPushPlugin.prototype.setApplicationIconBadgeNumber = function (badge) { JPushPlugin.prototype.setApplicationIconBadgeNumber = function (badge) {
if (this.isPlatformIOS()) { if (this.isPlatformIOS()) {
this.call_native("setApplicationIconBadgeNumber", [badge], null); this.call_native('setApplicationIconBadgeNumber', [badge], null)
} }
} }
JPushPlugin.prototype.getApplicationIconBadgeNumber = function (callback) { JPushPlugin.prototype.getApplicationIconBadgeNumber = function (callback) {
if (this.isPlatformIOS()) { if (this.isPlatformIOS()) {
this.call_native("getApplicationIconBadgeNumber", [], callback); this.call_native('getApplicationIconBadgeNumber', [], callback)
}
}
// 判断系统设置中是否对本应用启用通知。
// iOS: 返回值如果大于 0,代表通知开启;0: 通知关闭。
// UIRemoteNotificationTypeNone = 0,
// UIRemoteNotificationTypeBadge = 1 << 0,
// UIRemoteNotificationTypeSound = 1 << 1,
// UIRemoteNotificationTypeAlert = 1 << 2,
// UIRemoteNotificationTypeNewsstandContentAvailability = 1 << 3,
// Android: 返回值 1 代表通知启用、0: 通知关闭。
JPushPlugin.prototype.getUserNotificationSettings = function (callback) {
if (this.isPlatformIOS()) {
this.call_native('getUserNotificationSettings', [], callback)
} else if (device.platform == 'Android') {
this.call_native('areNotificationEnabled', [], callback)
} }
} }
// Android methods // Android methods
JPushPlugin.prototype.setDebugMode = function (mode) { JPushPlugin.prototype.setDebugMode = function (mode) {
if(device.platform == "Android") { if (device.platform == 'Android') {
this.call_native("setDebugMode", [mode], null); this.call_native('setDebugMode', [mode], null)
} }
} }
JPushPlugin.prototype.setBasicPushNotificationBuilder = function () { JPushPlugin.prototype.setBasicPushNotificationBuilder = function () {
if(device.platform == "Android") { if (device.platform == 'Android') {
data = []; data = []
this.call_native("setBasicPushNotificationBuilder", data, null); this.call_native('setBasicPushNotificationBuilder', data, null)
} }
} }
JPushPlugin.prototype.setCustomPushNotificationBuilder = function () { JPushPlugin.prototype.setCustomPushNotificationBuilder = function () {
if(device.platform == "Android") { if (device.platform == 'Android') {
data = []; data = []
this.call_native("setCustomPushNotificationBuilder", data, null); this.call_native('setCustomPushNotificationBuilder', data, null)
} }
} }
JPushPlugin.prototype.receiveMessageInAndroidCallback = function (data) { JPushPlugin.prototype.receiveMessageInAndroidCallback = function (data) {
try { try {
console.log("JPushPlugin:receiveMessageInAndroidCallback"); data = JSON.stringify(data)
data = JSON.stringify(data); console.log('JPushPlugin:receiveMessageInAndroidCallback: ' + data)
var bToObj = JSON.parse(data); this.receiveMessage = JSON.parse(data)
this.receiveMessage = bToObj cordova.fireDocumentEvent('jpush.receiveMessage', this.receiveMessage)
cordova.fireDocumentEvent('jpush.receiveMessage', null);
} catch(exception) { } catch(exception) {
console.log("JPushPlugin:pushCallback " + exception); console.log('JPushPlugin:pushCallback ' + exception)
} }
} }
JPushPlugin.prototype.openNotificationInAndroidCallback = function (data) { JPushPlugin.prototype.openNotificationInAndroidCallback = function (data) {
try { try {
console.log("JPushPlugin:openNotificationInAndroidCallback"); data = JSON.stringify(data)
data = JSON.stringify(data); console.log('JPushPlugin:openNotificationInAndroidCallback: ' + data)
var bToObj = JSON.parse(data); this.openNotification = JSON.parse(data)
this.openNotification = bToObj; cordova.fireDocumentEvent('jpush.openNotification', this.openNotification)
cordova.fireDocumentEvent('jpush.openNotification', null);
} catch(exception) { } catch(exception) {
console.log(exception); console.log(exception)
} }
} }
JPushPlugin.prototype.receiveNotificationInAndroidCallback = function (data) { JPushPlugin.prototype.receiveNotificationInAndroidCallback = function (data) {
try { try {
console.log("JPushPlugin:receiveNotificationInAndroidCallback"); data = JSON.stringify(data)
data = JSON.stringify(data); console.log('JPushPlugin:receiveNotificationInAndroidCallback: ' + data)
var bToObj = JSON.parse(data); this.receiveNotification = JSON.parse(data)
this.receiveNotification = bToObj; cordova.fireDocumentEvent('jpush.receiveNotification', this.receiveNotification)
cordova.fireDocumentEvent('jpush.receiveNotification', null);
} catch(exception) { } catch(exception) {
console.log(exception); console.log(exception)
} }
} }
JPushPlugin.prototype.clearAllNotification = function () { JPushPlugin.prototype.clearAllNotification = function () {
if(device.platform == "Android") { if (device.platform == 'Android') {
data = []; data = []
this.call_native("clearAllNotification", data, null); this.call_native('clearAllNotification', data, null)
} }
} }
JPushPlugin.prototype.clearNotificationById = function (notificationId) { JPushPlugin.prototype.clearNotificationById = function (notificationId) {
if(device.platform == "Android") { if (device.platform == 'Android') {
data = []; data = []
this.call_native("clearNotificationById", [notificationId], null); this.call_native('clearNotificationById', [notificationId], null)
} }
} }
JPushPlugin.prototype.setLatestNotificationNum = function (num) { JPushPlugin.prototype.setLatestNotificationNum = function (num) {
if(device.platform == "Android") { if (device.platform == 'Android') {
this.call_native("setLatestNotificationNum", [num], null); this.call_native('setLatestNotificationNum', [num], null)
} }
} }
JPushPlugin.prototype.setDebugMode = function (mode) { JPushPlugin.prototype.setDebugMode = function (mode) {
if(device.platform == "Android") { if (device.platform == 'Android') {
this.call_native("setDebugMode", [mode], null); this.call_native('setDebugMode', [mode], null)
} }
} }
JPushPlugin.prototype.addLocalNotification = function (builderId, content, title, JPushPlugin.prototype.addLocalNotification = function (builderId, content, title,
notificationID, broadcastTime, extras) { notificationID, broadcastTime, extras) {
if(device.platform == "Android") { if (device.platform == 'Android') {
data = [builderId, content, title, notificationID, broadcastTime, extras]; data = [builderId, content, title, notificationID, broadcastTime, extras]
this.call_native("addLocalNotification", data, null); this.call_native('addLocalNotification', data, null)
} }
} }
JPushPlugin.prototype.removeLocalNotification = function (notificationID) { JPushPlugin.prototype.removeLocalNotification = function (notificationID) {
if(device.platform == "Android") { if (device.platform == 'Android') {
this.call_native("removeLocalNotification", [notificationID], null); this.call_native('removeLocalNotification', [notificationID], null)
} }
} }
JPushPlugin.prototype.clearLocalNotifications = function () { JPushPlugin.prototype.clearLocalNotifications = function () {
if(device.platform == "Android") { if (device.platform == 'Android') {
data = []; data = []
this.call_native("clearLocalNotifications", data, null); this.call_native('clearLocalNotifications', data, null)
} }
} }
JPushPlugin.prototype.reportNotificationOpened = function (msgID) { JPushPlugin.prototype.reportNotificationOpened = function (msgID) {
if(device.platform == "Android") { if (device.platform == 'Android') {
this.call_native("reportNotificationOpened", [msgID], null); this.call_native('reportNotificationOpened', [msgID], null)
} }
} }
@@ -325,8 +334,8 @@ JPushPlugin.prototype.reportNotificationOpened = function(msgID) {
*在 Portal 上展示给开发者。 *在 Portal 上展示给开发者。
*/ */
JPushPlugin.prototype.setStatisticsOpen = function (mode) { JPushPlugin.prototype.setStatisticsOpen = function (mode) {
if(device.platform == "Android") { if (device.platform == 'Android') {
this.call_native("setStatisticsOpen", [mode], null); this.call_native('setStatisticsOpen', [mode], null)
} }
} }
@@ -335,29 +344,29 @@ JPushPlugin.prototype.setStatisticsOpen = function(mode) {
* 具体可看:http://docs.jpush.io/client/android_api/#android-60 * 具体可看:http://docs.jpush.io/client/android_api/#android-60
*/ */
JPushPlugin.prototype.requestPermission = function () { JPushPlugin.prototype.requestPermission = function () {
if(device.platform == "Android") { if (device.platform == 'Android') {
this.call_native("requestPermission", [], null); this.call_native('requestPermission', [], null)
} }
} }
JPushPlugin.prototype.setSilenceTime = function (startHour, startMinute, endHour, endMinute) { JPushPlugin.prototype.setSilenceTime = function (startHour, startMinute, endHour, endMinute) {
if (device.platform == "Android") { if (device.platform == 'Android') {
this.call_native("setSilenceTime", [startHour, startMinute, endHour, endMinute], null); this.call_native('setSilenceTime', [startHour, startMinute, endHour, endMinute], null)
} }
} }
JPushPlugin.prototype.setPushTime = function (weekdays, startHour, endHour) { JPushPlugin.prototype.setPushTime = function (weekdays, startHour, endHour) {
if (device.platform == "Android") { if (device.platform == 'Android') {
this.call_native("setPushTime", [weekdays, startHour, endHour], null); this.call_native('setPushTime', [weekdays, startHour, endHour], null)
} }
} }
if (!window.plugins) { if (!window.plugins) {
window.plugins = {}; window.plugins = {}
} }
if (!window.plugins.jPushPlugin) { if (!window.plugins.jPushPlugin) {
window.plugins.jPushPlugin = new JPushPlugin(); window.plugins.jPushPlugin = new JPushPlugin()
} }
module.exports = new JPushPlugin(); module.exports = new JPushPlugin()