Compare commits

...

33 Commits

Author SHA1 Message Date
Hevin Lau
4f8288107e Merge branch 'dev' 2016-09-22 18:02:41 +08:00
pikacode
0342577830 iOS - update support iOS 10
1.支持 iOS 10 设备推送。
2016-09-22 17:06:30 +08:00
E.B
116ac90492 iOS - update SDK v2.1.9
1.更新 iOS SDK v2.1.9
2016-09-22 14:15:14 +08:00
Hevin
a525ddc7df Update Android SDK to 2.1.9 2016-09-19 10:17:56 +08:00
E.B
149083b8f4 iOS fix spelling errors
1.修改拼写错误
2016-08-01 10:34:50 +08:00
Hevin Lau
be7b9aa8ac Update README & license. 2016-08-01 00:08:51 +08:00
Hevin
714a811ef2 Merge remote-tracking branch 'refs/remotes/origin/master' into dev 2016-07-22 11:22:04 +08:00
Hevin
13120cb88e Format README 2016-07-21 17:09:58 +08:00
Hevin
a365c632d4 Merge remote-tracking branch 'refs/remotes/origin/dev' 2016-07-21 17:05:53 +08:00
Hevin
1d1d7bbec8 Update README 2016-07-21 17:04:24 +08:00
Hevin
abac27de1a Update plugin.xml 2016-07-21 17:02:33 +08:00
Hevin
9cc27db799 Format doc. 2016-07-21 16:34:07 +08:00
Hevin
0c6450231b Fix API doc. 2016-07-21 16:31:15 +08:00
Hevin
c3171e716a Merge remote-tracking branch 'refs/remotes/origin/dev' 2016-07-21 16:27:19 +08:00
Hevin
e24d15db97 Update API doc. 2016-07-21 16:25:37 +08:00
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
26 changed files with 791 additions and 569 deletions

100
README.md
View File

@@ -2,93 +2,73 @@
[![Build Status](https://travis-ci.org/jpush/jpush-phonegap-plugin.svg?branch=master)](https://travis-ci.org/jpush/jpush-phonegap-plugin)
[![QQ Group](https://img.shields.io/badge/QQ%20Group-413602425-red.svg)]()
[![release](https://img.shields.io/badge/release-2.2.1-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)
[![weibo](https://img.shields.io/badge/weibo-JPush-blue.svg)](http://weibo.com/jpush?refer_flag=1001030101_&is_all=1)
支持 iOS, Android 的 Cordova 推送插件。
> 如需要 IM 功能的插件,可关注 [JMessage PhoneGap Plugin](https://github.com/jpush/jmessage-phonegap-plugin)。
> QQ 交流群413602425
> 如需要短信验证码功能的插件,可关注 [JSMS Cordova Plugin](https://github.com/jpush/cordova-plugin-jsms)。
## 集成步骤
集成 JPush PhoneGap Plugin 有两种方法:
> QQ 交流群413602425。
### 在线安装
- 通过 Cordova Plugins 安装,要求 PhoneGap/Cordova CLI 5.0+
## Install
cordova plugin add jpush-phonegap-plugin --variable API_KEY=your_jpush_appkey
- 通过 Cordova Plugins 安装,要求 Cordova CLI 5.0+
- 直接通过 url 安装:
cordova plugin add jpush-phonegap-plugin --variable API_KEY=your_jpush_appkey
- 或直接通过 url 安装:
cordova plugin add https://github.com/jpush/jpush-phonegap-plugin.git --variable API_KEY=your_jpush_appkey
### 本地安装
使用 git 命令将 JPush PhoneGap 插件下载的本地,目录标记为 $JPUSH_PLUGIN_DIR
- 或下载到本地安装
git clone https://github.com/jpush/jpush-phonegap-plugin.git
cordova plugin add Your_Plugin_Path --variable API_KEY=your_jpush_appkey
cordova plugin add $JPUSH_PLUGIN_DIR --variable API_KEY=your_jpush_appkey
- [Android 手动安装文档地址](/doc/Android_handle_install.md)。
## Usage
### API
- [公共 API](/doc/Common_detail_api.md)
- [iOS API](/doc/iOS_API.md)
- [Android API](/doc/Android_detail_api.md)
- [iOS 手动安装文档地址](/doc/iOS_install.md)。
### Demo
插件项目中包含一个简单的 Demo。若想参考可以在 */example* 文件夹内找到并拷贝以下文件:
## Demo
插件项目中包含一个简单的 Demo。若想参考可以在 /example 文件夹内找到并拷贝以下文件:
src/example/index.html -> www/index.html
src/example/css/* -> www/css
src/example/js/* -> www/js
## 关于 PhoneGap build 云服务
example/index.html -> www/index.html
example/css/* -> www/css
example/js/* -> www/js
### 关于 PhoneGap build 云服务
该项目基于 Cordova 实现,目前无法使用 PhoneGap build 云服务进行打包,建议使用本地环境进行打包。
## API 说明
## FAQ
> 如果遇到了疑问,请优先参考 Demo 和 API 文档。若还无法解决,可访问[极光社区](http://community.jiguang.cn/)或 [Issues](https://github.com/jpush/jpush-phonegap-plugin/issues) 提问。
插件的 API 在 JPushPlugin.js 文件中,该文件的具体位置如下:
### Android
[Project]/assets/www/plugins/cn.jpush.phonegap.JPushPlugin/www
#### 在 Eclipse 中 import 工程之后出现:*Type CallbackContext cannot be resolved to a type*。
右键单击工程名 -> Build Path -> Config Build Path -> Projects -> 选中工程名称 -> CordovaLib -> 点击 add。
### iOS
[Project]/www/plugins/cn.jpush.phonegap.JPushPlugin/www
#### PushConfig.plist 文件中的字段都是什么意思?
- APP_KEY应用标识。
- CHANNEL渠道标识。
- IsProduction是否生产环境。
- IsIDFA是否使用 IDFA 启动 SDK。
### 具体的 API 请参考:
- [公共 API](/doc/Common_detail_api.md)。
- [iOS API](/doc/iOS_API.md)。
- [Android API](/doc/Android_detail_api.md)。
#### 收不到推送了。
请首先按照正确方式再次配置证书、描述文件,具体可参考 [iOS 证书设置指南](http://docs.jpush.io/client/ios_tutorials/#ios_1)。
## 常见问题
## Support
- QQ 群413602425
- [JPush 官网文档](http://docs.jpush.io/)
- [极光社区](http://community.jiguang.cn/)
若要使用 CLI 来编译项目,注意应使用 cordova compile 而不是 cordova build 命令,因为如果修改了插件安装时默认写入到 AndroidManifest.xml
中的代码cordova build 可能会导致对 AndroidManifest.xml 的修改。
Cordova CLI 的具体用法可参考 [Cordova CLI 官方文档](https://cordova.apache.org/docs/en/latest/reference/cordova-cli/index.html)。
## Contribute
Please contribute! [Look at the issues](https://github.com/jpush/jpush-phonegap-plugin/issues).
### 1. Android
Eclipse 中 import PhoneGap 工程之后出现:*Type CallbackContext cannot be resolved to a type*。
解决方案Eclipse 中右键单击工程名Build Path -> Config Build Path -> Projects -> 选中工程名称 -> CordovaLib -> 点击 add。
### 2. iOS
- 收不到推送:
请首先按照正确方式再次配置证书、描述文件,具体可参考 [iOS 证书设置指南](http://docs.jpush.io/client/ios_tutorials/#ios_1)。
- 设置 PushConfig.plist
- APP_KEY应用标识。
- CHANNEL渠道标识。
- IsProduction是否生产环境。
- IsIDFA是否使用 IDFA 启动 SDK。
## 更多
- QQ 群413602425。
- [JPush 官网文档](http://docs.jpush.io/)。
- 如有问题可访问[极光社区](http://community.jpush.cn/)。
## License
MIT © [JiGuang](/license)

View File

@@ -86,14 +86,13 @@ JPush SDK 会恢复正常的默认行为。(因为保存在本地的状态数
#### 代码示例
window.plugins.jPushPlugin.resumePush(callback)
var onCallback = function(data) {
if(data > 0) {
window.plugins.jPushPlugin.isPushStopped(function (result) {
if (result == 0) {
// 开启
} else {
} else {
// 关闭
}
}
}
})
## 获取 RegistrationID
@@ -226,7 +225,7 @@ JPush SDK 会以广播的形式发送 RegistrationID 到应用程序。
var alertContent;
if(device.platform == "Android") {
alertContent = window.plugins.jPushPlugin.openNotification.alert;
alertContent = event.alert;
} else {
alertContent = event.aps.alert;
}
@@ -280,7 +279,7 @@ ps点击通知后传递的 json object 保存在 window.plugins.jPushPlugin.o
var alertContent;
if(device.platform == "Android") {
alertContent = window.plugins.jPushPlugin.receiveNotification.alert;
alertContent = event.alert;
} else {
alertContent = event.aps.alert;
}
@@ -339,7 +338,7 @@ ps点击通知后传递的 json object 保存在 window.plugins.jPushPlugin.r
try{
var message
if(device.platform == "Android") {
message = window.plugins.jPushPlugin.receiveMessage.message;
message = event.message;
} else {
message = event.content;
}

View File

@@ -47,7 +47,7 @@
try {
var alertContent;
if (device.platform == "Android") {
alertContent = window.plugins.jPushPlugin.openNotification.alert;
alertContent = event.alert;
} else {
alertContent = event.aps.alert;
}
@@ -61,7 +61,7 @@
try {
var alertContent;
if (device.platform == "Android") {
alertContent = window.plugins.jPushPlugin.receiveNotification.alert;
alertContent = event.alert;
} else {
alertContent = event.aps.alert;
}
@@ -75,7 +75,7 @@
try {
var message;
if (device.platform == "Android") {
message = window.plugins.jPushPlugin.receiveMessage.message;
message = event.message;
} else {
message = event.content;
}

21
license Normal file
View File

@@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) JiGuang <support@jpush.cn> (jiguang.cn)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

View File

@@ -1,9 +1,9 @@
{
"name": "jpush-phonegap-plugin",
"version": "2.2.2",
"version": "2.2.6",
"description": "JPush for cordova plugin",
"cordova": {
"id": "cordova-plugin-JPush",
"id": "jpush-phonegap-plugin",
"platforms": [
"ios",
"android"
@@ -30,8 +30,8 @@
"peerDependencies": {
"cordova-plugin-device": ">=1.0.0"
},
"author": "jpush",
"license": "Apache 2.0 License",
"author": "JiGuang",
"license": "MIT",
"bugs": {
"url": "https://github.com/jpush/jpush-phonegap-plugin/issues"
},

View File

@@ -1,199 +1,184 @@
<?xml version="1.0" encoding="UTF-8"?>
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
xmlns:android="http://schemas.android.com/apk/res/android"
id="cordova-plugin-JPush"
version="2.2.2">
xmlns:android="http://schemas.android.com/apk/res/android"
id="jpush-phonegap-plugin"
version="2.2.5">
<name>JPush Plugin</name>
<description>JPush for cordova plugin</description>
<author>JPush</author>
<keywords>JPush,push</keywords>
<license>Apache 2.0 License</license>
<license>MIT License</license>
<preference name="API_KEY" />
<engines>
<engine name="cordova" version=">=3.0"/>
<engine name="cordova" version=">=3.0" />
</engines>
<dependency id="org.apache.cordova.device" url="https://github.com/apache/cordova-plugin-device.git"/>
<!-- dependencies -->
<dependency id="cordova-plugin-device" />
<js-module src="www/JPushPlugin.js" name="JPushPlugin">
<clobbers target="JPush"/>
<clobbers target="JPush" />
</js-module>
<platform name="ios">
<config-file target="config.xml" parent="/*">
<feature name="JPushPlugin">
<param name="ios-package" value="JPushPlugin"/>
</feature>
</config-file>
<config-file target="config.xml" parent="/*">
<feature name="JPushPlugin">
<param name="ios-package" value="JPushPlugin" />
</feature>
</config-file>
<header-file src="src/ios/Plugins/JPushPlugin.h"/>
<source-file src="src/ios/Plugins/JPushPlugin.m"/>
<header-file src="src/ios/Plugins/JPushPlugin.h" />
<source-file src="src/ios/Plugins/JPushPlugin.m" />
<header-file src="src/ios/lib/JPUSHService.h" />
<source-file src="src/ios/lib/jpush-ios-2.1.8.a" framework="true" />
<header-file src="src/ios/Plugins/AppDelegate+JPush.h"/>
<source-file src="src/ios/Plugins/AppDelegate+JPush.m"/>
<resource-file src="src/ios/PushConfig.plist" />
<framework src="CFNetwork.framework" weak="true" />
<framework src="CoreFoundation.framework" weak="true" />
<framework src="CoreTelephony.framework" weak="true" />
<framework src="SystemConfiguration.framework" weak="true" />
<framework src="CoreGraphics.framework" weak="true" />
<framework src="Foundation.framework" weak="true" />
<framework src="UIKit.framework" weak="true" />
<framework src="Security.framework" weak="true" />
<framework src="libz.tbd" weak="true" />
<framework src="AdSupport.framework" weak="true" />
<header-file src="src/ios/lib/JPUSHService.h" />
<source-file src="src/ios/lib/jpush-ios-2.1.9.a" framework="true" />
<header-file src="src/ios/Plugins/AppDelegate+JPush.h" />
<source-file src="src/ios/Plugins/AppDelegate+JPush.m" />
<resource-file src="src/ios/PushConfig.plist" />
<framework src="CFNetwork.framework" weak="true" />
<framework src="CoreFoundation.framework" weak="true" />
<framework src="CoreTelephony.framework" weak="true" />
<framework src="SystemConfiguration.framework" weak="true" />
<framework src="CoreGraphics.framework" weak="true" />
<framework src="Foundation.framework" weak="true" />
<framework src="UIKit.framework" weak="true" />
<framework src="Security.framework" weak="true" />
<framework src="libz.tbd" weak="true" />
<framework src="AdSupport.framework" weak="true" />
<framework src="UserNotifications.framework" weak="true" />
<config-file target="*PushConfig.plist" parent="APP_KEY">
<string>$API_KEY</string>
</config-file>
</platform>
<config-file target="*PushConfig.plist" parent="APP_KEY">
<string>$API_KEY</string>
</config-file>
</platform>
<platform name="android">
<config-file target="res/xml/config.xml" parent="/*">
<feature name="JPushPlugin">
<param name="android-package" value="cn.jpush.phonegap.JPushPlugin"/>
<param name="android-package" value="cn.jpush.phonegap.JPushPlugin" />
</feature>
</config-file>
<framework src="com.android.support:support-v4:24.0.0" />
<config-file target="AndroidManifest.xml" parent="/manifest">
<!-- Required 一些系统要求的权限,如访问网络等-->
<uses-permission android:name="$PACKAGE_NAME.permission.JPUSH_MESSAGE"/>
<uses-permission android:name="android.permission.RECEIVE_USER_PRESENT"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.WAKE_LOCK"/>
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.VIBRATE"/>
<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
<uses-permission android:name="android.permission.WRITE_SETTINGS"/>
<permission
android:name="$PACKAGE_NAME.permission.JPUSH_MESSAGE"
android:protectionLevel="signature"/>
<uses-permission android:name="$PACKAGE_NAME.permission.JPUSH_MESSAGE" />
<uses-permission android:name="android.permission.RECEIVE_USER_PRESENT" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
<uses-permission android:name="android.permission.WRITE_SETTINGS" />
<permission android:name="$PACKAGE_NAME.permission.JPUSH_MESSAGE" android:protectionLevel="signature" />
</config-file>
<config-file target="AndroidManifest.xml" parent="/manifest/application">
<!-- Required SDK核心功能-->
<activity
android:name="cn.jpush.android.ui.PushActivity"
android:theme="@android:style/Theme.Translucent.NoTitleBar"
android:configChanges="orientation|keyboardHidden">
<activity android:name="cn.jpush.android.ui.PushActivity" android:theme="@android:style/Theme.Translucent.NoTitleBar" android:configChanges="orientation|keyboardHidden">
<intent-filter>
<action android:name="cn.jpush.android.ui.PushActivity"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="$PACKAGE_NAME"/>
<action android:name="cn.jpush.android.ui.PushActivity" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="$PACKAGE_NAME" />
</intent-filter>
</activity>
<!-- Rich push 核心功能 since 2.0.6-->
<activity
android:name="cn.jpush.android.ui.PopWinActivity"
android:theme="@style/MyDialogStyle"
android:exported="false">
<activity android:name="cn.jpush.android.ui.PopWinActivity" android:theme="@style/MyDialogStyle" android:exported="false">
</activity>
<!-- Required SDK核心功能-->
<service
android:name="cn.jpush.android.service.DownloadService"
android:enabled="true"
android:exported="false">
<service android:name="cn.jpush.android.service.DownloadService"
android:enabled="true"
android:exported="false">
</service>
<!-- Required SDK 核心功能-->
<service
android:name="cn.jpush.android.service.PushService"
android:enabled="true"
android:exported="false">
<service android:name="cn.jpush.android.service.PushService"
android:enabled="true"
android:exported="false">
<intent-filter>
<action android:name="cn.jpush.android.intent.REGISTER"/>
<action android:name="cn.jpush.android.intent.REPORT"/>
<action android:name="cn.jpush.android.intent.PushService"/>
<action android:name="cn.jpush.android.intent.PUSH_TIME"/>
<action android:name="cn.jpush.android.intent.REGISTER" />
<action android:name="cn.jpush.android.intent.REPORT" />
<action android:name="cn.jpush.android.intent.PushService" />
<action android:name="cn.jpush.android.intent.PUSH_TIME" />
</intent-filter>
</service>
<!-- Required SDK核心功能-->
<receiver
android:name="cn.jpush.android.service.PushReceiver"
android:enabled="true">
<receiver android:name="cn.jpush.android.service.PushReceiver"
android:enabled="true">
<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 显示通知栏 -->
<category android:name="$PACKAGE_NAME"/>
<category android:name="$PACKAGE_NAME" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.USER_PRESENT"/>
<action android:name="android.net.conn.CONNECTIVITY_CHANGE"/>
<action android:name="android.intent.action.USER_PRESENT" />
<action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
</intent-filter>
<!-- Optional -->
<intent-filter>
<action android:name="android.intent.action.PACKAGE_ADDED"/>
<action android:name="android.intent.action.PACKAGE_REMOVED"/>
<action android:name="android.intent.action.PACKAGE_ADDED" />
<action android:name="android.intent.action.PACKAGE_REMOVED" />
</intent-filter>
</receiver>
<!-- since 1.8.0 option 可选项。用于同一设备中不同应用的JPush服务相互拉起的功能。 -->
<!-- 若不启用该功能可删除该组件,将不拉起其他应用也不能被其他应用拉起 -->
<service
android:name="cn.jpush.android.service.DaemonService"
android:enabled="true"
android:exported="true">
<intent-filter >
<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"/>
<category android:name="$PACKAGE_NAME" />
</intent-filter>
</service>
<!-- User defined. For test only 用户自定义的广播接收器 -->
<receiver
android:name="cn.jpush.phonegap.MyReceiver"
android:enabled="true">
<receiver android:name="cn.jpush.phonegap.MyReceiver" android:enabled="true">
<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 显示通知栏 -->
<category android:name="$PACKAGE_NAME"/>
<category android:name="$PACKAGE_NAME" />
</intent-filter>
<intent-filter>
<action android:name="cn.jpush.android.intent.REGISTRATION"/>
<action android:name="cn.jpush.android.intent.REGISTRATION" />
<!-- Required 用户注册SDK的intent -->
<action android:name="cn.jpush.android.intent.UNREGISTRATION"/>
<action android:name="cn.jpush.android.intent.MESSAGE_RECEIVED"/>
<action android:name="cn.jpush.android.intent.UNREGISTRATION" />
<action android:name="cn.jpush.android.intent.MESSAGE_RECEIVED" />
<!-- Required 用户接收SDK消息的intent -->
<action android:name="cn.jpush.android.intent.NOTIFICATION_RECEIVED"/>
<action android:name="cn.jpush.android.intent.NOTIFICATION_RECEIVED" />
<!-- Required 用户接收SDK通知栏信息的intent -->
<action android:name="cn.jpush.android.intent.NOTIFICATION_OPENED"/>
<action android:name="cn.jpush.android.intent.NOTIFICATION_OPENED" />
<!-- Required 用户打开自定义通知栏的intent -->
<action android:name="cn.jpush.android.intent.ACTION_RICHPUSH_CALLBACK"/>
<action android:name="cn.jpush.android.intent.ACTION_RICHPUSH_CALLBACK" />
<!-- Optional 用户接受Rich Push Javascript 回调函数的intent -->
<category android:name="$PACKAGE_NAME"/>
<category android:name="$PACKAGE_NAME" />
</intent-filter>
</receiver>
<!-- Required SDK核心功能-->
<receiver android:name="cn.jpush.android.service.AlarmReceiver"/>
<receiver android:name="cn.jpush.android.service.AlarmReceiver" />
<!-- Required. Enable it you can get statistics data with channel -->
<meta-data android:name="JPUSH_CHANNEL" android:value="developer-default"/>
<meta-data android:name="JPUSH_APPKEY" android:value="$API_KEY"/>
<meta-data android:name="JPUSH_CHANNEL" android:value="developer-default" />
<meta-data android:name="JPUSH_APPKEY" android:value="$API_KEY" />
</config-file>
<source-file src="src/android/jpush-android-2.1.7.jar" target-dir="libs"/>
<source-file src="src/android/armeabi/libjpush217.so" target-dir="libs/armeabi"/>
<source-file src="src/android/armeabi-v7a/libjpush217.so" target-dir="libs/armeabi-v7a"/>
<source-file src="src/android/arm64-v8a/libjpush217.so" target-dir="libs/arm64-v8a"/>
<source-file src="src/android/x86/libjpush217.so" target-dir="libs/x86"/>
<source-file src="src/android/x86_64/libjpush217.so" target-dir="libs/x86_64"/>
<source-file src="src/android/jpush-android-2.1.9.jar" target-dir="libs" />
<source-file src="src/android/armeabi/libjpush219.so" target-dir="libs/armeabi" />
<source-file src="src/android/armeabi-v7a/libjpush219.so" target-dir="libs/armeabi-v7a" />
<source-file src="src/android/arm64-v8a/libjpush219.so" target-dir="libs/arm64-v8a" />
<source-file src="src/android/x86/libjpush219.so" target-dir="libs/x86" />
<source-file src="src/android/x86_64/libjpush219.so" target-dir="libs/x86_64" />
<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/jpush_notification_icon.png" target-dir="res/drawable"/>
<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/jpush_notification_icon.png" target-dir="res/drawable" />
<!-- Rich Push resources -->
<source-file src="src/android/ic_richpush_actionbar_back.png" target-dir="res/drawable" />

View File

@@ -1,8 +1,11 @@
package cn.jpush.phonegap;
import android.annotation.TargetApi;
import android.app.Activity;
import android.app.AppOpsManager;
import android.content.Context;
import android.support.v4.app.NotificationManagerCompat;
import android.content.pm.ApplicationInfo;
import android.os.Build;
import android.text.TextUtils;
import android.util.Log;
@@ -14,6 +17,8 @@ import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.HashMap;
@@ -84,10 +89,10 @@ public class JPushPlugin extends CordovaPlugin {
@Override
public void initialize(CordovaInterface cordova, CordovaWebView webView) {
super.initialize(cordova, webView);
Log.i(TAG, "JPush initialize.");
Log.i(TAG, "---------------- initialize" + "-" + openNotificationAlert
+ "-" + notificationAlert);
super.initialize(cordova, webView);
JPushInterface.init(cordova.getActivity().getApplicationContext());
cordovaActivity = cordova.getActivity();
@@ -138,7 +143,7 @@ public class JPushPlugin extends CordovaPlugin {
}
private static JSONObject getMessageObject(String message,
Map<String, Object> extras) {
Map<String, Object> extras) {
JSONObject data = new JSONObject();
try {
data.put("message", message);
@@ -172,7 +177,7 @@ public class JPushPlugin extends CordovaPlugin {
}
private static JSONObject getNotificationObject(String title,
String alert, Map<String, Object> extras) {
String alert, Map<String, Object> extras) {
JSONObject data = new JSONObject();
try {
data.put("title", title);
@@ -180,7 +185,7 @@ public class JPushPlugin extends CordovaPlugin {
JSONObject jExtras = new JSONObject();
for (Entry<String, Object> entry : extras.entrySet()) {
if (entry.getKey().equals("cn.jpush.android.EXTRA")) {
JSONObject jo = null;
JSONObject jo;
if (TextUtils.isEmpty((String) entry.getValue())) {
jo = new JSONObject();
} else {
@@ -222,7 +227,7 @@ public class JPushPlugin extends CordovaPlugin {
}
static void transmitNotificationOpen(String title, String alert,
Map<String, Object> extras) {
Map<String, Object> extras) {
if (instance == null) {
return;
}
@@ -240,7 +245,7 @@ public class JPushPlugin extends CordovaPlugin {
}
static void transmitNotificationReceive(String title, String alert,
Map<String, Object> extras) {
Map<String, Object> extras) {
if (instance == null) {
return;
}
@@ -259,7 +264,7 @@ public class JPushPlugin extends CordovaPlugin {
@Override
public boolean execute(final String action, final JSONArray data,
final CallbackContext callbackContext) throws JSONException {
final CallbackContext callbackContext) throws JSONException {
if (!methodList.contains(action)) {
return false;
}
@@ -314,13 +319,11 @@ public class JPushPlugin extends CordovaPlugin {
}
void areNotificationEnabled(JSONArray data, final CallbackContext callback) {
NotificationManagerCompat nmc = NotificationManagerCompat.from(
cordova.getActivity().getApplicationContext());
int isEnabled;
if (nmc.areNotificationsEnabled()) {
if (hasPermission("OP_POST_NOTIFICATION")) {
isEnabled = 1;
} else {
isEnabled = 0;
isEnabled = 0;
}
callback.success(isEnabled);
}
@@ -436,7 +439,7 @@ public class JPushPlugin extends CordovaPlugin {
}
void setBasicPushNotificationBuilder(JSONArray data,
CallbackContext callbackContext) {
CallbackContext callbackContext) {
BasicPushNotificationBuilder builder = new BasicPushNotificationBuilder(
this.cordova.getActivity());
builder.developerArg0 = "Basic builder 1";
@@ -450,22 +453,16 @@ public class JPushPlugin extends CordovaPlugin {
}
/**
* 自定义推送通知栏样式,需要自己实现具体代码。
* http://docs.jiguang.cn/client/android_tutorials/#_11
*/
* 自定义推送通知栏样式,需要自己实现具体代码。
* http://docs.jiguang.cn/client/android_tutorials/#_11
*/
void setCustomPushNotificationBuilder(JSONArray data,
CallbackContext callbackContext) {
CallbackContext callbackContext) {
// CustomPushNotificationBuilder builder = new CustomPushNotificationBuilder(
// this.cordova.getActivity(), R.layout.test_notification_layout,
// R.id.icon, R.id.title, R.id.text);
// builder.developerArg0 = "Custom Builder 1";
// JPushInterface.setPushNotificationBuilder(2, builder);
// JSONObject obj = new JSONObject();
// try {
// obj.put("id", 2);
// } catch (JSONException e) {
// e.printStackTrace();
// }
// JPushInterface.setDefaultPushNotificationBuilder(builder);
}
void clearAllNotification(JSONArray data, CallbackContext callbackContext) {
@@ -600,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.

View File

@@ -7,7 +7,9 @@
//
#import "AppDelegate.h"
#import <UserNotifications/UserNotifications.h>
#import "JPUSHService.h"
@interface AppDelegate (JPush)
@interface AppDelegate (JPush) <JPUSHRegisterDelegate>
-(void)registerForIos10RemoteNotification;
@end

View File

@@ -8,8 +8,11 @@
#import "AppDelegate+JPush.h"
#import "JPushPlugin.h"
#import "JPUSHService.h"
#import <objc/runtime.h>
#import <AdSupport/AdSupport.h>
#import <UserNotifications/UserNotifications.h>
@implementation AppDelegate (JPush)
@@ -24,12 +27,13 @@
}
-(instancetype)init_plus{
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationDidLaunch:) name:@"UIApplicationDidFinishLaunchingNotification" object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationDidLaunch:) name:UIApplicationDidFinishLaunchingNotification object:nil];
return [self init_plus];
}
-(void)applicationDidLaunch:(NSNotification *)notification{
if (notification) {
[self registerForIos10RemoteNotification];
[JPushPlugin setLaunchOptions:notification.userInfo];
}
}
@@ -62,4 +66,33 @@
// [[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];
}
-(void)jpushNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(NSInteger))completionHandler{
NSMutableDictionary *userInfo = [NSMutableDictionary dictionaryWithDictionary:notification.request.content.userInfo];
[userInfo setValue:kJPushPluginiOS10ForegroundReceiveNotification forKey:@"JPushNotificationType"];
[[NSNotificationCenter defaultCenter] postNotificationName:kJPushPluginiOS10ForegroundReceiveNotification object:userInfo];
completionHandler(UNNotificationPresentationOptionBadge|UNNotificationPresentationOptionSound|UNNotificationPresentationOptionAlert);
}
-(void)jpushNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)())completionHandler{
NSMutableDictionary *userInfo = [NSMutableDictionary dictionaryWithDictionary:response.notification.request.content.userInfo];
[userInfo setValue:kJPushPluginiOS10ClickNotification forKey:@"JPushNotificationType"];
[[NSNotificationCenter defaultCenter] postNotificationName:kJPushPluginiOS10ClickNotification object:userInfo];
completionHandler();
}
-(void)registerForIos10RemoteNotification{
if ([[UIDevice currentDevice].systemVersion floatValue] >= 10.0) {
#ifdef NSFoundationVersionNumber_iOS_9_x_Max
JPUSHRegisterEntity * entity = [[JPUSHRegisterEntity alloc] init];
entity.types = UNAuthorizationOptionAlert|UNAuthorizationOptionBadge|UNAuthorizationOptionSound;
[JPUSHService registerForRemoteNotificationConfig:entity delegate:self];
#endif
}
}
@end

View File

@@ -9,6 +9,9 @@
#import <Cordova/CDV.h>
#define kJPushPluginReceiveNotification @"JPushPluginReceiveNofication"
#define kJPushPluginiOS10ForegroundReceiveNotification @"kJPushPluginiOS10ForegroundReceiveNotification"
#define kJPushPluginiOS10ClickNotification @"kJPushPluginiOS10ClickNotification"
@interface JPushPlugin : CDVPlugin{
@@ -67,7 +70,7 @@
* jpush.setTagsWithAlias 设置标签、别名完成
* jpush.receiveMessage 收到自定义消息
* jpush.receiveNotification 前台收到推送
* jpush.backgoundNotification 后台收到推送
* jpush.backgroundNotification 后台收到推送
*/
@end

View File

@@ -10,6 +10,8 @@
#import "JPUSHService.h"
#import <UIKit/UIKit.h>
#import <AdSupport/AdSupport.h>
#import <UserNotifications/UserNotifications.h>
#import "AppDelegate+JPush.h"
static NSString *const JP_APP_KEY = @"APP_KEY";
static NSString *const JP_APP_CHANNEL = @"CHANNEL";
@@ -18,6 +20,30 @@ static NSString *const JP_APP_ISIDFA = @"IsIDFA";
static NSString *const JPushConfigFileName = @"PushConfig";
static NSDictionary *_launchOptions = nil;
#define WEAK_SELF(weakSelf) __weak __typeof(&*self)weakSelf = self;
@implementation NSDictionary (JPush)
-(NSString*)toJsonString{
NSError *error;
NSData *data = [NSJSONSerialization dataWithJSONObject:self options:0 error:&error];
NSString *jsonString = [[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding];
return jsonString;
}
@end
@implementation NSString (JPush)
-(NSDictionary*)toDictionary{
NSError *error;
NSData *jsonData = [self dataUsingEncoding:NSUTF8StringEncoding];
NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:jsonData options:0 error:&error];
return dict;
}
@end
@interface JPushPlugin()
@end
@implementation JPushPlugin
#pragma mark-
@@ -29,22 +55,6 @@ static NSDictionary *_launchOptions = nil;
[JPushPlugin registerForRemoteNotification];
}
+(void)registerForRemoteNotification{
if ([[UIDevice currentDevice].systemVersion floatValue] >= 8.0) {
//categories
[JPUSHService registerForRemoteNotificationTypes:(UIUserNotificationTypeBadge |
UIUserNotificationTypeSound |
UIUserNotificationTypeAlert)
categories:nil];
} else {
//categories nil
[JPUSHService registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge |
UIRemoteNotificationTypeSound |
UIRemoteNotificationTypeAlert)
categories:nil];
}
}
-(void)isPushStopped:(CDVInvokedUrlCommand*)command{
NSNumber *result;
if ([[UIApplication sharedApplication] isRegisteredForRemoteNotifications]) {
@@ -92,19 +102,23 @@ static NSDictionary *_launchOptions = nil;
name:kJPushPluginReceiveNotification
object:nil];
if (_launchOptions) {
NSDictionary *userInfo = [_launchOptions
valueForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
if ([userInfo count] >0) {
NSError *error;
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:userInfo options:0 error:&error];
NSString *jsonString = [[NSString alloc]initWithData:jsonData encoding:NSUTF8StringEncoding];
if (!error) {
dispatch_async(dispatch_get_main_queue(), ^{
[self.commandDelegate evalJs:[NSString stringWithFormat:@"cordova.fireDocumentEvent('jpush.openNotification',%@)",jsonString]];
});
[defaultCenter addObserver:self
selector:@selector(networkDidReceiveNotification:)
name:kJPushPluginiOS10ForegroundReceiveNotification
object:nil];
}
[defaultCenter addObserver:self
selector:@selector(networkDidReceiveNotification:)
name:kJPushPluginiOS10ClickNotification
object:nil];
if (_launchOptions) {
NSDictionary *userInfo = [_launchOptions valueForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
if ([userInfo count] >0) {
dispatch_async(dispatch_get_main_queue(), ^{
[self.commandDelegate evalJs:[NSString stringWithFormat:@"cordova.fireDocumentEvent('jpush.openNotification',%@)",[userInfo toJsonString]]];
});
}
}
@@ -248,7 +262,14 @@ static NSDictionary *_launchOptions = nil;
}
-(void)deleteLocalNotificationWithIdentifierKey:(CDVInvokedUrlCommand*)command{
[JPUSHService deleteLocalNotificationWithIdentifierKey:(NSString*)command.arguments[0]];
NSString *identifier = [command argumentAtIndex:0];
if ([UIDevice currentDevice].systemVersion.floatValue >= 10.0) {
JPushNotificationIdentifier *jpid = [JPushNotificationIdentifier new];
jpid.identifiers = @[identifier];
[JPUSHService removeNotification:jpid];
}else{
[JPUSHService deleteLocalNotificationWithIdentifierKey:identifier];
}
}
-(void)clearAllLocalNotifications:(CDVInvokedUrlCommand*)command{
@@ -260,7 +281,22 @@ static NSDictionary *_launchOptions = nil;
}
-(void)getUserNotificationSettings:(CDVInvokedUrlCommand*)command{
if ([[UIDevice currentDevice].systemVersion floatValue] >= 8.0) {
if ([[UIDevice currentDevice].systemVersion floatValue] >= 10.0) {
UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
WEAK_SELF(weakSelf);
[center getNotificationSettingsWithCompletionHandler:^(UNNotificationSettings * _Nonnull settings) {
NSMutableDictionary *dict = [NSMutableDictionary dictionary];
dict[@"authorizationStatus"] = @(settings.authorizationStatus);
dict[@"soundSetting"] = @(settings.soundSetting);
dict[@"badgeSetting"] = @(settings.badgeSetting);
dict[@"alertSetting"] = @(settings.alertSetting);
dict[@"notificationCenterSetting"] = @(settings.notificationCenterSetting);
dict[@"lockScreenSetting"] = @(settings.lockScreenSetting);
dict[@"carPlaySetting"] = @(settings.carPlaySetting);
dict[@"alertStyle"] = @(settings.alertStyle);
[weakSelf handleResultWithValue:dict command:command];
}];
}else if ([[UIDevice currentDevice].systemVersion floatValue] >= 8.0) {
UIUserNotificationSettings *settings = [[UIApplication sharedApplication] currentUserNotificationSettings];
UIUserNotificationType type = settings.types;
NSNumber *number = [NSNumber numberWithInteger:type];
@@ -270,10 +306,9 @@ static NSDictionary *_launchOptions = nil;
NSNumber *number = [NSNumber numberWithInteger:type];
[self handleResultWithValue:number command:command];
}
}
#pragma mark-
#pragma mark -
+(void)setLaunchOptions:(NSDictionary *)theLaunchOptions{
_launchOptions = theLaunchOptions;
@@ -294,11 +329,6 @@ static NSDictionary *_launchOptions = nil;
NSNumber * isProduction = [plistData valueForKey:JP_APP_ISPRODUCTION];
NSNumber *isIDFA = [plistData valueForKey:JP_APP_ISIDFA];
if (!appkey || appkey.length == 0) {
NSLog(@"error: app key not found in PushConfig.plist ");
assert(0);
}
NSString *advertisingId = nil;
if(isIDFA){
advertisingId = [[[ASIdentifierManager sharedManager] advertisingIdentifier] UUIDString];
@@ -311,6 +341,24 @@ static NSDictionary *_launchOptions = nil;
}
+(void)registerForRemoteNotification{
[(AppDelegate*)[UIApplication sharedApplication].delegate registerForIos10RemoteNotification];
if ([[UIDevice currentDevice].systemVersion floatValue] >= 8.0) {
//categories
[JPUSHService registerForRemoteNotificationTypes:(UIUserNotificationTypeBadge |
UIUserNotificationTypeSound |
UIUserNotificationTypeAlert)
categories:nil];
} else if([[UIDevice currentDevice].systemVersion floatValue] < 8.0){
//categories nil
[JPUSHService registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge |
UIRemoteNotificationTypeSound |
UIRemoteNotificationTypeAlert)
categories:nil];
}
}
#pragma mark js
-(void)handleResultWithValue:(id)value command:(CDVInvokedUrlCommand*)command{
CDVPluginResult *result = nil;
@@ -337,50 +385,35 @@ static NSDictionary *_launchOptions = nil;
#pragma mark
-(void)tagsWithAliasCallback:(int)resultCode tags:(NSSet *)tags alias:(NSString *)alias{
NSDictionary *dict = @{@"resultCode":[NSNumber numberWithInt:resultCode],
@"tags" :tags == nil ? [NSNull null] : [tags allObjects],
@"alias" :alias == nil ? [NSNull null] : alias
};
NSError *error;
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:dict options:0 error:&error];
NSString *jsonString = [[NSString alloc]initWithData:jsonData encoding:NSUTF8StringEncoding];
dispatch_async(dispatch_get_main_queue(), ^{
[self.commandDelegate evalJs:[NSString stringWithFormat:@"cordova.fireDocumentEvent('jpush.setTagsWithAlias',%@)",jsonString]];
[self.commandDelegate evalJs:[NSString stringWithFormat:@"cordova.fireDocumentEvent('jpush.setTagsWithAlias',%@)",[dict toJsonString]]];
});
}
- (void)networkDidReceiveMessage:(NSNotification *)notification {
if (notification) {
NSDictionary *userInfo = [notification userInfo];
//NSLog(@"%@",userInfo);
NSError *error;
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:userInfo options:0 error:&error];
NSString *jsonString = [[NSString alloc]initWithData:jsonData encoding:NSUTF8StringEncoding];
//NSLog(@"%@",jsonString);
dispatch_async(dispatch_get_main_queue(), ^{
[self.commandDelegate evalJs:[NSString stringWithFormat:@"cordova.fireDocumentEvent('jpush.receiveMessage',%@)",jsonString]];
[self.commandDelegate evalJs:[NSString stringWithFormat:@"cordova.fireDocumentEvent('jpush.receiveMessage',%@)",[notification.userInfo toJsonString]]];
[self.commandDelegate evalJs:[NSString stringWithFormat:@"window.plugins.jPushPlugin.receiveMessageIniOSCallback('%@')",jsonString]];
[self.commandDelegate evalJs:[NSString stringWithFormat:@"window.plugins.jPushPlugin.receiveMessageIniOSCallback('%@')",[notification.userInfo toJsonString]]];
});
}
}
-(void)networkDidReceiveNotification:(id)notification{
-(void)networkDidReceiveNotification:(NSNotification *)notification{
NSError *error;
NSDictionary *userInfo = [notification object];
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:userInfo options:0 error:&error];
NSString *jsonString = [[NSString alloc]initWithData:jsonData encoding:NSUTF8StringEncoding];
switch ([UIApplication sharedApplication].applicationState) {
case UIApplicationStateActive:{
//
@@ -404,10 +437,10 @@ static NSDictionary *_launchOptions = nil;
break;
}
default:
//do nothing
break;
//do nothing
break;
}
}
@end

176
src/ios/lib/JPUSHService.h Executable file → Normal file
View File

@@ -9,23 +9,102 @@
* Copyright (c) 2011 ~ 2015 Shenzhen HXHG. All rights reserved.
*/
#define JPUSH_VERSION_NUMBER 2.1.8
#define JPUSH_VERSION_NUMBER 2.1.9
#import <Foundation/Foundation.h>
@class CLRegion;
@class UILocalNotification;
@class CLLocation;
@class UNNotificationCategory;
@class UNNotificationSettings;
@class UNNotificationRequest;
@class UNNotification;
@protocol JPUSHRegisterDelegate;
extern NSString *const kJPFNetworkIsConnectingNotification; // 正在连接中
extern NSString *const kJPFNetworkDidSetupNotification; // 建立连接
extern NSString *const kJPFNetworkDidCloseNotification; // 关闭连接
extern NSString *const kJPFNetworkDidRegisterNotification; // 注册成功
extern NSString *const kJPFNetworkFailedRegisterNotification; //注册失败
extern NSString *const kJPFNetworkDidLoginNotification; // 登录成功
extern NSString *const kJPFNetworkDidReceiveMessageNotification; // 收到消息(非APNS)
extern NSString *const kJPFServiceErrorNotification; // 错误提示
@class CLLocation;
/*!
* 通知注册实体类
*/
@interface JPUSHRegisterEntity : NSObject
/*!
* 支持的类型
* badge,sound,alert
*/
@property (nonatomic, assign) NSInteger types;
/*!
* 注入的类别
* iOS10 UNNotificationCategory
* iOS8-iOS9 UIUserNotificationCategory
*/
@property (nonatomic, strong) NSSet *categories;
@end
/*!
* 进行删除、查找推送实体类
*/
@interface JPushNotificationIdentifier : NSObject<NSCopying, NSCoding>
@property (nonatomic, copy) NSArray<NSString *> *identifiers; // 推送的标识数组
@property (nonatomic, copy) UILocalNotification *notificationObj NS_DEPRECATED_IOS(4_0, 10_0); // iOS10以下可以传UILocalNotification对象数据iOS10以上无效
@property (nonatomic, assign) BOOL delivered NS_AVAILABLE_IOS(10_0); // 在通知中心显示的或待推送的标志默认为NOYES表示在通知中心显示的NO表示待推送的
@property (nonatomic, copy) void (^findCompletionHandler)(NSArray *results); // 用于查询回调,调用[findNotification:]方法前必须设置results为返回相应对象数组iOS10以下返回UILocalNotification对象数组iOS10以上根据delivered传入值返回UNNotification或UNNotificationRequest对象数组delivered传入YES则返回UNNotification对象数组否则返回UNNotificationRequest对象数组
@end
/*!
* 推送内容实体类
*/
@interface JPushNotificationContent : NSObject<NSCopying, NSCoding>
@property (nonatomic, copy) NSString *title; // 推送标题
@property (nonatomic, copy) NSString *subtitle; // 推送副标题
@property (nonatomic, copy) NSString *body; // 推送内容
@property (nonatomic, copy) NSNumber *badge; // 角标的数字。如果不需要改变角标传@(-1)
@property (nonatomic, copy) NSString *action NS_DEPRECATED_IOS(8_0, 10_0); // 弹框的按钮显示的内容IOS 8默认为"打开", 其他默认为"启动",iOS10以上无效
@property (nonatomic, copy) NSString *categoryIdentifier; // 行为分类标识
@property (nonatomic, copy) NSDictionary *userInfo; // 本地推送时可以设置userInfo来增加附加信息远程推送时设置的payload推送内容作为此userInfo
@property (nonatomic, copy) NSString *sound; // 声音名称,不设置则为默认声音
@property (nonatomic, copy) NSArray *attachments NS_AVAILABLE_IOS(10_0); // 附件iOS10以上有效需要传入UNNotificationAttachment对象数组类型
@property (nonatomic, copy) NSString *threadIdentifier NS_AVAILABLE_IOS(10_0); // 线程或与推送请求相关对话的标识iOS10以上有效可用来对推送进行分组
@property (nonatomic, copy) NSString *launchImageName NS_AVAILABLE_IOS(10_0); // 启动图片名iOS10以上有效从推送启动时将会用到
@end
/*!
* 推送触发方式实体类
* 注dateComponents、timeInterval、region在iOS10以上可选择其中一个参数传入有效值如果同时传入值会根据优先级I、II、III使其中一种触发方式生效fireDate为iOS10以下根据时间触发时须传入的参数
*/
@interface JPushNotificationTrigger : NSObject<NSCopying, NSCoding>
@property (nonatomic, assign) BOOL repeat; // 设置是否重复默认为NO
@property (nonatomic, copy) NSDate *fireDate NS_DEPRECATED_IOS(2_0, 10_0); // 用来设置触发推送的时间iOS10以上无效
@property (nonatomic, copy) CLRegion *region NS_AVAILABLE_IOS(8_0); // 用来设置触发推送的位置iOS8以上有效iOS10以上优先级为I应用需要有允许使用定位的授权
@property (nonatomic, copy) NSDateComponents *dateComponents NS_AVAILABLE_IOS(10_0); // 用来设置触发推送的日期时间iOS10以上有效优先级为II
@property (nonatomic, assign) NSTimeInterval timeInterval NS_AVAILABLE_IOS(10_0); // 用来设置触发推送的时间iOS10以上有效优先级为III
@end
/*!
* 注册或更新推送实体类
*/
@interface JPushNotificationRequest : NSObject<NSCopying, NSCoding>
@property (nonatomic, copy) NSString *requestIdentifier; // 推送请求标识
@property (nonatomic, copy) JPushNotificationContent *content; // 设置推送的具体内容
@property (nonatomic, copy) JPushNotificationTrigger *trigger; // 设置推送的触发方式
@property (nonatomic, copy) void (^completionHandler)(id result); // 注册或更新推送成功回调iOS10以上成功则result为UNNotificationRequest对象失败则result为nil;iOS10以下成功result为UILocalNotification对象失败则result为nil
@end
/*!
* JPush 核心头文件
@@ -77,12 +156,20 @@ extern NSString *const kJPFServiceErrorNotification; // 错误提示
* @abstract 注册要处理的远程通知类型
*
* @param types 通知类型
* @param categories
* @param categories 类别组
*
* @discussion
*/
+ (void)registerForRemoteNotificationTypes:(NSUInteger)types
categories:(NSSet *)categories;
/*!
* @abstract 新版本的注册方法兼容iOS10
*
* @param config 注册通知配置
* @param delegate 代理
*
*/
+ (void)registerForRemoteNotificationConfig:(JPUSHRegisterEntity *)config delegate:(id<JPUSHRegisterDelegate>)delegate;
+ (void)registerDeviceToken:(NSData *)deviceToken;
@@ -99,14 +186,14 @@ extern NSString *const kJPFServiceErrorNotification; // 错误提示
/*!
* 下面的接口是可选的
* 设置标签和(或)别名若参数为nil则忽略若是空对象则清空详情请参考文档http://docs.jpush.io/client/ios_api/#api-ios
* 设置标签和(或)别名若参数为nil则忽略若是空对象则清空详情请参考文档http://docs.jiguang.cn/client/ios_api/#api-ios
* setTags:alias:fetchCompletionHandle:是新的设置标签别名的方法不再需要显示声明回调函数只需要在block里面处理设置结果即可.
* WARN: 使用block时需要注意循环引用问题
*/
+ (void) setTags:(NSSet *)tags
alias:(NSString *)alias
callbackSelector:(SEL)cbSelector
target:(id)theTarget __attribute__((deprecated("JPush 2.1.1 版本已过期")));;
target:(id)theTarget __attribute__((deprecated("JPush 2.1.1 版本已过期")));
+ (void) setTags:(NSSet *)tags
alias:(NSString *)alias
@@ -192,6 +279,35 @@ callbackSelector:(SEL)cbSelector
///----------------------------------------------------
/// @name Local Notification 本地通知
///----------------------------------------------------
/*!
* @abstract 注册或更新推送 (支持iOS10并兼容iOS10以下版本)
*
* JPush 2.1.9新接口
* @param request JPushNotificationRequest类型设置推送的属性设置已有推送的request.requestIdentifier即更新已有的推送否则为注册新推送更新推送仅仅在iOS10以上有效结果通过request.completionHandler返回
* @discussion 旧的注册本地推送接口被废弃,使用此接口可以替换
*
*/
+ (void)addNotification:(JPushNotificationRequest *)request;
/*!
* @abstract 移除推送 (支持iOS10并兼容iOS10以下版本)
*
* JPush 2.1.9新接口
* @param identifier JPushNotificationIdentifier类型iOS10以上identifier设置为nil则移除所有在通知中心显示推送和待推送请求也可以通过设置identifier.delivered和identifier.identifiers来移除相应在通知中心显示推送或待推送请求identifier.identifiers如果设置为nil或空数组则移除相应标志下所有在通知中心显示推送或待推送请求iOS10以下identifier设置为nil则移除所有推送identifier.delivered属性无效另外可以通过identifier.notificationObj传入特定推送对象来移除此推送。
* @discussion 旧的所有删除推送接口被废弃,使用此接口可以替换
*
*/
+ (void)removeNotification:(JPushNotificationIdentifier *)identifier;
/*!
* @abstract 查找推送 (支持iOS10并兼容iOS10以下版本)
*
* JPush 2.1.9新接口
* @param identifier JPushNotificationIdentifier类型iOS10以上可以通过设置identifier.delivered和identifier.identifiers来查找相应在通知中心显示推送或待推送请求identifier.identifiers如果设置为nil或空数组则返回相应标志下所有在通知中心显示推送或待推送请求iOS10以下identifier.delivered属性无效identifier.identifiers如果设置nil或空数组则返回所有推送。须要设置identifier.findCompletionHandler回调才能得到查找结果通过(NSArray *results)返回相应对象数组。
* @discussion 旧的查找推送接口被废弃,使用此接口可以替换
*
*/
+ (void)findNotification:(JPushNotificationIdentifier *)identifier;
/*!
* @abstract 本地推送最多支持64个
@@ -204,7 +320,7 @@ callbackSelector:(SEL)cbSelector
* @param userInfo 自定义参数,可以用来标识推送和增加附加信息
* @param soundName 自定义通知声音设置为nil为默认声音
*
* @discussion 最多支持 64 个定义
* @discussion 最多支持 64 个定义,此方法被[addNotification:]方法取代
*/
+ (UILocalNotification *)setLocalNotification:(NSDate *)fireDate
alertBody:(NSString *)alertBody
@@ -212,7 +328,7 @@ callbackSelector:(SEL)cbSelector
alertAction:(NSString *)alertAction
identifierKey:(NSString *)notificationKey
userInfo:(NSDictionary *)userInfo
soundName:(NSString *)soundName;
soundName:(NSString *)soundName __attribute__((deprecated("JPush 2.1.9 版本已过期")));
/*!
* @abstract 本地推送 (支持 iOS8 新参数)
@@ -221,6 +337,7 @@ callbackSelector:(SEL)cbSelector
* @param region 自定义参数
* @param regionTriggersOnce 自定义参数
* @param category 自定义参数
* @discussion 此方法被[addNotification:]方法取代
*/
+ (UILocalNotification *)setLocalNotification:(NSDate *)fireDate
alertBody:(NSString *)alertBody
@@ -231,7 +348,7 @@ callbackSelector:(SEL)cbSelector
soundName:(NSString *)soundName
region:(CLRegion *)region
regionTriggersOnce:(BOOL)regionTriggersOnce
category:(NSString *)category NS_AVAILABLE_IOS(8_0);
category:(NSString *)category NS_AVAILABLE_IOS(8_0) __attribute__((deprecated("JPush 2.1.9 版本已过期")));
/*!
* @abstract 前台展示本地推送
@@ -239,35 +356,39 @@ callbackSelector:(SEL)cbSelector
* @param notification 本地推送对象
* @param notificationKey 需要前台显示的本地推送通知的标示符
*
* @discussion 默认App在前台运行时不会进行弹窗在程序接收通知调用此接口可实现指定的推送弹窗。
* @discussion 默认App在前台运行时不会进行弹窗在程序接收通知调用此接口可实现指定的推送弹窗。--iOS10以下还可继续使用iOS10以上在[UNUserNotificationCenterDelegate willPresentNotification:withCompletionHandler:]方法中调用completionHandler(UNNotificationPresentationOptionSound | UNNotificationPresentationOptionAlert);即可
*/
+ (void)showLocalNotificationAtFront:(UILocalNotification *)notification
identifierKey:(NSString *)notificationKey;
identifierKey:(NSString *)notificationKey __attribute__((deprecated("JPush 2.1.9 版本已过期")));
/*!
* @abstract 删除本地推送定义
*
* @param notificationKey 本地推送标示符
* @param myUILocalNotification 本地推送对象
* @discussion 此方法被[removeNotification:]方法取代
*/
+ (void)deleteLocalNotificationWithIdentifierKey:(NSString *)notificationKey;
+ (void)deleteLocalNotificationWithIdentifierKey:(NSString *)notificationKey __attribute__((deprecated("JPush 2.1.9 版本已过期")));
/*!
* @abstract 删除本地推送定义
* @discussion 此方法被[removeNotification:]方法取代
*/
+ (void)deleteLocalNotification:(UILocalNotification *)localNotification;
+ (void)deleteLocalNotification:(UILocalNotification *)localNotification __attribute__((deprecated("JPush 2.1.9 版本已过期")));
/*!
* @abstract 获取指定通知
*
* @param notificationKey 本地推送标示符
* @return 本地推送对象数组, [array count]为0时表示没找到
* @discussion 此方法被[findNotification:]方法取代
*/
+ (NSArray *)findLocalNotificationWithIdentifier:(NSString *)notificationKey;
+ (NSArray *)findLocalNotificationWithIdentifier:(NSString *)notificationKey __attribute__((deprecated("JPush 2.1.9 版本已过期")));
/*!
* @abstract 清除所有本地推送对象
* @discussion 此方法被[removeNotification:]方法取代
*/
+ (void)clearAllLocalNotifications;
+ (void)clearAllLocalNotifications __attribute__((deprecated("JPush 2.1.9 版本已过期")));
///----------------------------------------------------
@@ -313,11 +434,13 @@ callbackSelector:(SEL)cbSelector
*
* JPush 支持根据 registrationID 来进行推送.
* 如果你需要此功能, 应该通过此接口获取到 registrationID 后, 上报到你自己的服务器端, 并保存下来.
*
* registrationIDCompletionHandler:是新增的获取registrationID的方法需要在block中获取registrationID,resCode为返回码,模拟器调用此接口resCode返回1011,registrationID返回nil.
* 更多的理解请参考 JPush 的文档网站.
*/
+ (NSString *)registrationID;
+ (void)registrationIDCompletionHandler:(void(^)(int resCode,NSString *registrationID))completionHandler;
/*!
* @abstract 打开日志级别到 Debug
*
@@ -342,5 +465,26 @@ callbackSelector:(SEL)cbSelector
*/
+ (void)setLogOFF;
@end
@class UNUserNotificationCenter;
@class UNNotificationResponse;
@protocol JPUSHRegisterDelegate <NSObject>
/*
* @brief handle UserNotifications.framework [willPresentNotification:withCompletionHandler:]
* @param center [UNUserNotificationCenter currentNotificationCenter] 新特性用户通知中心
* @param notification 前台得到的的通知对象
* @param completionHandler 该callback中的options 请使用UNNotificationPresentationOptions
*/
- (void)jpushNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(NSInteger options))completionHandler;
/*
* @brief handle UserNotifications.framework [didReceiveNotificationResponse:withCompletionHandler:]
* @param center [UNUserNotificationCenter currentNotificationCenter] 新特性用户通知中心
* @param response 通知响应对象
* @param completionHandler
*/
- (void)jpushNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void(^)())completionHandler;
@end

View File

@@ -1,215 +1,210 @@
var JPushPlugin = function () {}
var JPushPlugin = function(){
};
//private plugin function
// private plugin function
JPushPlugin.prototype.receiveMessage = {}
JPushPlugin.prototype.openNotification = {}
JPushPlugin.prototype.receiveNotification = {}
JPushPlugin.prototype.isPlatformIOS = function() {
var isPlatformIOS = device.platform == "iPhone"
|| device.platform == "iPad"
|| device.platform == "iPod touch"
|| device.platform == "iOS";
return isPlatformIOS;
JPushPlugin.prototype.isPlatformIOS = function () {
var isPlatformIOS = device.platform == 'iPhone'
|| device.platform == 'iPad'
|| device.platform == 'iPod touch'
|| device.platform == 'iOS'
return isPlatformIOS
}
JPushPlugin.prototype.error_callback = function(msg) {
console.log("Javascript Callback Error: " + msg);
JPushPlugin.prototype.error_callback = function (msg) {
console.log('Javascript Callback Error: ' + msg)
}
JPushPlugin.prototype.call_native = function(name, args, callback) {
ret = cordova.exec(callback, this.error_callback, 'JPushPlugin', name, args);
return ret;
JPushPlugin.prototype.call_native = function (name, args, callback) {
ret = cordova.exec(callback, this.error_callback, 'JPushPlugin', name, args)
return ret
}
// public methods
JPushPlugin.prototype.init = function() {
if(this.isPlatformIOS()) {
var data = [];
this.call_native("initial", data, null);
} else {
data = [];
this.call_native("init", data, null);
}
JPushPlugin.prototype.init = function () {
if (this.isPlatformIOS()) {
var data = []
this.call_native('initial', data, null)
} else {
data = []
this.call_native('init', data, null)
}
}
JPushPlugin.prototype.getRegistrationID = function(callback) {
try {
var data = [];
this.call_native("getRegistrationID", [data], callback);
} catch(exception) {
console.log(exception);
}
JPushPlugin.prototype.getRegistrationID = function (callback) {
try {
var data = []
this.call_native('getRegistrationID', [data], callback)
} catch(exception) {
console.log(exception)
}
}
JPushPlugin.prototype.stopPush = function() {
data = [];
this.call_native("stopPush", data, null);
JPushPlugin.prototype.stopPush = function () {
data = []
this.call_native('stopPush', data, null)
}
JPushPlugin.prototype.resumePush = function() {
data = [];
this.call_native("resumePush", data, null);
JPushPlugin.prototype.resumePush = function () {
data = []
this.call_native('resumePush', data, null)
}
JPushPlugin.prototype.isPushStopped = function(callback) {
data = [];
this.call_native("isPushStopped", data, callback);
JPushPlugin.prototype.isPushStopped = function (callback) {
data = []
this.call_native('isPushStopped', data, callback)
}
// iOS methods
JPushPlugin.prototype.setTagsWithAlias = function(tags, alias) {
try {
if(tags == null) {
this.setAlias(alias);
return;
}
if(alias == null) {
this.setTags(tags);
return;
}
var arrayTagWithAlias = [tags];
arrayTagWithAlias.unshift(alias);
this.call_native("setTagsWithAlias", arrayTagWithAlias, null);
} catch(exception) {
console.log(exception);
}
}
JPushPlugin.prototype.setTags = function(tags) {
try {
this.call_native("setTags", tags, null);
} catch(exception) {
console.log(exception);
}
}
JPushPlugin.prototype.setAlias = function(alias) {
try {
this.call_native("setAlias", [alias], null);
} catch(exception) {
console.log(exception);
}
}
JPushPlugin.prototype.setBadge = function(value) {
if(this.isPlatformIOS()) {
try {
this.call_native("setBadge", [value], null);
} catch(exception) {
console.log(exception);
}
}
}
JPushPlugin.prototype.resetBadge = function() {
if(this.isPlatformIOS()) {
try {
var data = [];
this.call_native("resetBadge", [data], null);
} catch(exception) {
console.log(exception);
}
}
}
JPushPlugin.prototype.setDebugModeFromIos = function() {
if(this.isPlatformIOS()) {
var data = [];
this.call_native("setDebugModeFromIos", [data], null);
}
}
JPushPlugin.prototype.setLogOFF = function() {
if(this.isPlatformIOS()) {
var data = [];
this.call_native("setLogOFF", [data], null);
}
}
JPushPlugin.prototype.setCrashLogON = function() {
if (this.isPlatformIOS()) {
var data = [];
this.call_native("crashLogON", [data], null);
JPushPlugin.prototype.setTagsWithAlias = function (tags, alias) {
try {
if (tags == null) {
this.setAlias(alias)
return
}
}
JPushPlugin.prototype.addLocalNotificationForIOS = function(delayTime, content,
badge, notificationID, extras) {
if (this.isPlatformIOS()) {
var data = [delayTime, content, badge, notificationID, extras];
this.call_native("setLocalNotification", data, null);
if (alias == null) {
this.setTags(tags)
return
}
var arrayTagWithAlias = [tags]
arrayTagWithAlias.unshift(alias)
this.call_native('setTagsWithAlias', arrayTagWithAlias, null)
} catch(exception) {
console.log(exception)
}
}
JPushPlugin.prototype.deleteLocalNotificationWithIdentifierKeyInIOS = function(
identifierKey) {
if (this.isPlatformIOS()) {
var data = [identifierKey];
this.call_native("deleteLocalNotificationWithIdentifierKey", data, null);
JPushPlugin.prototype.setTags = function (tags) {
try {
this.call_native('setTags', tags, null)
} catch(exception) {
console.log(exception)
}
}
JPushPlugin.prototype.setAlias = function (alias) {
try {
this.call_native('setAlias', [alias], null)
} catch(exception) {
console.log(exception)
}
}
JPushPlugin.prototype.setBadge = function (value) {
if (this.isPlatformIOS()) {
try {
this.call_native('setBadge', [value], null)
} catch(exception) {
console.log(exception)
}
}
}
JPushPlugin.prototype.clearAllLocalNotifications = function(){
if (this.isPlatformIOS()) {
var data = [];
this.call_native("clearAllLocalNotifications", data, null);
JPushPlugin.prototype.resetBadge = function () {
if (this.isPlatformIOS()) {
try {
var data = []
this.call_native('resetBadge', [data], null)
} catch(exception) {
console.log(exception)
}
}
}
JPushPlugin.prototype.setLocation = function(latitude, longitude){
if (this.isPlatformIOS()) {
var data = [latitude, longitude];
this.call_native("setLocation", data, null);
}
JPushPlugin.prototype.setDebugModeFromIos = function () {
if (this.isPlatformIOS()) {
var data = []
this.call_native('setDebugModeFromIos', [data], null)
}
}
JPushPlugin.prototype.receiveMessageIniOSCallback = function(data) {
try {
console.log("JPushPlugin:receiveMessageIniOSCallback--data:" + data);
var bToObj = JSON.parse(data);
var content = bToObj.content;
console.log(content);
} catch(exception) {
console.log("JPushPlugin:receiveMessageIniOSCallback" + exception);
}
JPushPlugin.prototype.setLogOFF = function () {
if (this.isPlatformIOS()) {
var data = []
this.call_native('setLogOFF', [data], null)
}
}
JPushPlugin.prototype.startLogPageView = function(pageName) {
if(this.isPlatformIOS()) {
this.call_native("startLogPageView", [pageName], null);
}
JPushPlugin.prototype.setCrashLogON = function () {
if (this.isPlatformIOS()) {
var data = []
this.call_native('crashLogON', [data], null)
}
}
JPushPlugin.prototype.stopLogPageView = function(pageName) {
if(this.isPlatformIOS()) {
this.call_native("stopLogPageView", [pageName], null);
}
JPushPlugin.prototype.addLocalNotificationForIOS = function (delayTime, content,
badge, notificationID, extras) {
if (this.isPlatformIOS()) {
var data = [delayTime, content, badge, notificationID, extras]
this.call_native('setLocalNotification', data, null)
}
}
JPushPlugin.prototype.beginLogPageView = function(pageName, duration) {
if(this.isPlatformIOS()) {
this.call_native("beginLogPageView", [pageName, duration], null);
}
JPushPlugin.prototype.deleteLocalNotificationWithIdentifierKeyInIOS = function (
identifierKey) {
if (this.isPlatformIOS()) {
var data = [identifierKey]
this.call_native('deleteLocalNotificationWithIdentifierKey', data, null)
}
}
JPushPlugin.prototype.setApplicationIconBadgeNumber = function(badge) {
if(this.isPlatformIOS()) {
this.call_native("setApplicationIconBadgeNumber", [badge], null);
}
JPushPlugin.prototype.clearAllLocalNotifications = function () {
if (this.isPlatformIOS()) {
var data = []
this.call_native('clearAllLocalNotifications', data, null)
}
}
JPushPlugin.prototype.getApplicationIconBadgeNumber = function(callback) {
if(this.isPlatformIOS()) {
this.call_native("getApplicationIconBadgeNumber", [], callback);
}
JPushPlugin.prototype.setLocation = function (latitude, longitude) {
if (this.isPlatformIOS()) {
var data = [latitude, longitude]
this.call_native('setLocation', data, null)
}
}
JPushPlugin.prototype.receiveMessageIniOSCallback = function (data) {
try {
console.log('JPushPlugin:receiveMessageIniOSCallback--data:' + data)
var bToObj = JSON.parse(data)
var content = bToObj.content
console.log(content)
} catch(exception) {
console.log('JPushPlugin:receiveMessageIniOSCallback' + exception)
}
}
JPushPlugin.prototype.startLogPageView = function (pageName) {
if (this.isPlatformIOS()) {
this.call_native('startLogPageView', [pageName], null)
}
}
JPushPlugin.prototype.stopLogPageView = function (pageName) {
if (this.isPlatformIOS()) {
this.call_native('stopLogPageView', [pageName], null)
}
}
JPushPlugin.prototype.beginLogPageView = function (pageName, duration) {
if (this.isPlatformIOS()) {
this.call_native('beginLogPageView', [pageName, duration], null)
}
}
JPushPlugin.prototype.setApplicationIconBadgeNumber = function (badge) {
if (this.isPlatformIOS()) {
this.call_native('setApplicationIconBadgeNumber', [badge], null)
}
}
JPushPlugin.prototype.getApplicationIconBadgeNumber = function (callback) {
if (this.isPlatformIOS()) {
this.call_native('getApplicationIconBadgeNumber', [], callback)
}
}
// 判断系统设置中是否对本应用启用通知。
// iOS: 返回值如果大于 0代表通知开启0: 通知关闭。
@@ -219,162 +214,159 @@ JPushPlugin.prototype.getApplicationIconBadgeNumber = function(callback) {
// 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);
}
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
JPushPlugin.prototype.setDebugMode = function(mode) {
if(device.platform == "Android") {
this.call_native("setDebugMode", [mode], null);
}
JPushPlugin.prototype.setDebugMode = function (mode) {
if (device.platform == 'Android') {
this.call_native('setDebugMode', [mode], null)
}
}
JPushPlugin.prototype.setBasicPushNotificationBuilder = function() {
if(device.platform == "Android") {
data = [];
this.call_native("setBasicPushNotificationBuilder", data, null);
}
JPushPlugin.prototype.setBasicPushNotificationBuilder = function () {
if (device.platform == 'Android') {
data = []
this.call_native('setBasicPushNotificationBuilder', data, null)
}
}
JPushPlugin.prototype.setCustomPushNotificationBuilder = function() {
if(device.platform == "Android") {
data = [];
this.call_native("setCustomPushNotificationBuilder", data, null);
}
JPushPlugin.prototype.setCustomPushNotificationBuilder = function () {
if (device.platform == 'Android') {
data = []
this.call_native('setCustomPushNotificationBuilder', data, null)
}
}
JPushPlugin.prototype.receiveMessageInAndroidCallback = function(data) {
try {
console.log("JPushPlugin:receiveMessageInAndroidCallback");
data = JSON.stringify(data);
var bToObj = JSON.parse(data);
this.receiveMessage = bToObj
cordova.fireDocumentEvent('jpush.receiveMessage', null);
} catch(exception) {
console.log("JPushPlugin:pushCallback " + exception);
}
JPushPlugin.prototype.receiveMessageInAndroidCallback = function (data) {
try {
data = JSON.stringify(data)
console.log('JPushPlugin:receiveMessageInAndroidCallback: ' + data)
this.receiveMessage = JSON.parse(data)
cordova.fireDocumentEvent('jpush.receiveMessage', this.receiveMessage)
} catch(exception) {
console.log('JPushPlugin:pushCallback ' + exception)
}
}
JPushPlugin.prototype.openNotificationInAndroidCallback = function(data) {
try {
console.log("JPushPlugin:openNotificationInAndroidCallback");
data = JSON.stringify(data);
var bToObj = JSON.parse(data);
this.openNotification = bToObj;
cordova.fireDocumentEvent('jpush.openNotification', null);
} catch(exception) {
console.log(exception);
}
JPushPlugin.prototype.openNotificationInAndroidCallback = function (data) {
try {
data = JSON.stringify(data)
console.log('JPushPlugin:openNotificationInAndroidCallback: ' + data)
this.openNotification = JSON.parse(data)
cordova.fireDocumentEvent('jpush.openNotification', this.openNotification)
} catch(exception) {
console.log(exception)
}
}
JPushPlugin.prototype.receiveNotificationInAndroidCallback = function(data) {
try{
console.log("JPushPlugin:receiveNotificationInAndroidCallback");
data = JSON.stringify(data);
var bToObj = JSON.parse(data);
this.receiveNotification = bToObj;
cordova.fireDocumentEvent('jpush.receiveNotification', null);
} catch(exception) {
console.log(exception);
}
JPushPlugin.prototype.receiveNotificationInAndroidCallback = function (data) {
try {
data = JSON.stringify(data)
console.log('JPushPlugin:receiveNotificationInAndroidCallback: ' + data)
this.receiveNotification = JSON.parse(data)
cordova.fireDocumentEvent('jpush.receiveNotification', this.receiveNotification)
} catch(exception) {
console.log(exception)
}
}
JPushPlugin.prototype.clearAllNotification = function() {
if(device.platform == "Android") {
data = [];
this.call_native("clearAllNotification", data, null);
}
JPushPlugin.prototype.clearAllNotification = function () {
if (device.platform == 'Android') {
data = []
this.call_native('clearAllNotification', data, null)
}
}
JPushPlugin.prototype.clearNotificationById = function(notificationId) {
if(device.platform == "Android") {
data = [];
this.call_native("clearNotificationById", [notificationId], null);
}
JPushPlugin.prototype.clearNotificationById = function (notificationId) {
if (device.platform == 'Android') {
data = []
this.call_native('clearNotificationById', [notificationId], null)
}
}
JPushPlugin.prototype.setLatestNotificationNum = function(num) {
if(device.platform == "Android") {
this.call_native("setLatestNotificationNum", [num], null);
}
JPushPlugin.prototype.setLatestNotificationNum = function (num) {
if (device.platform == 'Android') {
this.call_native('setLatestNotificationNum', [num], null)
}
}
JPushPlugin.prototype.setDebugMode = function(mode) {
if(device.platform == "Android") {
this.call_native("setDebugMode", [mode], null);
}
JPushPlugin.prototype.setDebugMode = function (mode) {
if (device.platform == 'Android') {
this.call_native('setDebugMode', [mode], null)
}
}
JPushPlugin.prototype.addLocalNotification = function(builderId, content, title,
notificationID, broadcastTime, extras) {
if(device.platform == "Android") {
data = [builderId, content, title, notificationID, broadcastTime, extras];
this.call_native("addLocalNotification", data, null);
}
JPushPlugin.prototype.addLocalNotification = function (builderId, content, title,
notificationID, broadcastTime, extras) {
if (device.platform == 'Android') {
data = [builderId, content, title, notificationID, broadcastTime, extras]
this.call_native('addLocalNotification', data, null)
}
}
JPushPlugin.prototype.removeLocalNotification = function(notificationID) {
if(device.platform == "Android") {
this.call_native("removeLocalNotification", [notificationID], null);
}
JPushPlugin.prototype.removeLocalNotification = function (notificationID) {
if (device.platform == 'Android') {
this.call_native('removeLocalNotification', [notificationID], null)
}
}
JPushPlugin.prototype.clearLocalNotifications = function() {
if(device.platform == "Android") {
data = [];
this.call_native("clearLocalNotifications", data, null);
}
JPushPlugin.prototype.clearLocalNotifications = function () {
if (device.platform == 'Android') {
data = []
this.call_native('clearLocalNotifications', data, null)
}
}
JPushPlugin.prototype.reportNotificationOpened = function(msgID) {
if(device.platform == "Android") {
this.call_native("reportNotificationOpened", [msgID], null);
}
JPushPlugin.prototype.reportNotificationOpened = function (msgID) {
if (device.platform == 'Android') {
this.call_native('reportNotificationOpened', [msgID], null)
}
}
/**
*是否开启统计分析功能,用于“用户使用时长”,“活跃用户”,“用户打开次数”的统计,并上报到服务器上,
*在 Portal 上展示给开发者。
*/
JPushPlugin.prototype.setStatisticsOpen = function(mode) {
if(device.platform == "Android") {
this.call_native("setStatisticsOpen", [mode], null);
}
JPushPlugin.prototype.setStatisticsOpen = function (mode) {
if (device.platform == 'Android') {
this.call_native('setStatisticsOpen', [mode], null)
}
}
/**
* 用于在 Android 6.0 及以上系统,申请一些权限
* 具体可看http://docs.jpush.io/client/android_api/#android-60
*/
JPushPlugin.prototype.requestPermission = function() {
if(device.platform == "Android") {
this.call_native("requestPermission", [], null);
}
JPushPlugin.prototype.requestPermission = function () {
if (device.platform == 'Android') {
this.call_native('requestPermission', [], null)
}
}
JPushPlugin.prototype.setSilenceTime = function(startHour, startMinute, endHour, endMinute) {
if (device.platform == "Android") {
this.call_native("setSilenceTime", [startHour, startMinute, endHour, endMinute], null);
}
JPushPlugin.prototype.setSilenceTime = function (startHour, startMinute, endHour, endMinute) {
if (device.platform == 'Android') {
this.call_native('setSilenceTime', [startHour, startMinute, endHour, endMinute], null)
}
}
JPushPlugin.prototype.setPushTime = function(weekdays, startHour, endHour) {
if (device.platform == "Android") {
this.call_native("setPushTime", [weekdays, startHour, endHour], null);
}
JPushPlugin.prototype.setPushTime = function (weekdays, startHour, endHour) {
if (device.platform == 'Android') {
this.call_native('setPushTime', [weekdays, startHour, endHour], null)
}
}
if(!window.plugins) {
window.plugins = {};
if (!window.plugins) {
window.plugins = {}
}
if(!window.plugins.jPushPlugin) {
window.plugins.jPushPlugin = new JPushPlugin();
if (!window.plugins.jPushPlugin) {
window.plugins.jPushPlugin = new JPushPlugin()
}
module.exports = new JPushPlugin();
module.exports = new JPushPlugin()