mirror of
https://github.com/jpush/jpush-phonegap-plugin.git
synced 2026-01-28 00:00:03 +08:00
Compare commits
164 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4f8288107e | ||
|
|
0342577830 | ||
|
|
116ac90492 | ||
|
|
a525ddc7df | ||
|
|
149083b8f4 | ||
|
|
be7b9aa8ac | ||
|
|
714a811ef2 | ||
|
|
13120cb88e | ||
|
|
a365c632d4 | ||
|
|
1d1d7bbec8 | ||
|
|
abac27de1a | ||
|
|
9cc27db799 | ||
|
|
0c6450231b | ||
|
|
c3171e716a | ||
|
|
e24d15db97 | ||
|
|
3101dcdd8e | ||
|
|
a46da92fa1 | ||
|
|
5547d5716e | ||
|
|
7da0a25db0 | ||
|
|
0c74ff328d | ||
|
|
2065ad44ce | ||
|
|
cbe8e511f2 | ||
|
|
9a47c88873 | ||
|
|
684039b044 | ||
|
|
356de48d31 | ||
|
|
d412b10d3e | ||
|
|
44345d9753 | ||
|
|
5f93fc3f49 | ||
|
|
673a402c51 | ||
|
|
09e0d62360 | ||
|
|
b4830d4ef7 | ||
|
|
2c3bf53792 | ||
|
|
78ebe0e787 | ||
|
|
54f87adde2 | ||
|
|
c101552938 | ||
|
|
c918efb99a | ||
|
|
9be760e65e | ||
|
|
cea1eb85fa | ||
|
|
f8c56b5aa1 | ||
|
|
0bb6838477 | ||
|
|
c6b8a6f2f6 | ||
|
|
42fbe62d19 | ||
|
|
d3ea41f513 | ||
|
|
5ff7d14bec | ||
|
|
1c41e96f42 | ||
|
|
48adf59ec8 | ||
|
|
3369072687 | ||
|
|
8e7e957884 | ||
|
|
c615f8255e | ||
|
|
7ffec241fa | ||
|
|
de32f4a057 | ||
|
|
1cd7ecf3e5 | ||
|
|
b01b4bf259 | ||
|
|
f8efb4f010 | ||
|
|
870fc12c0d | ||
|
|
dc2cdda00c | ||
|
|
1c96487869 | ||
|
|
8d24ce7c48 | ||
|
|
280846779d | ||
|
|
1ba048ee1b | ||
|
|
e4500dd513 | ||
|
|
a511072101 | ||
|
|
851ff1f23b | ||
|
|
5cf5bd39d1 | ||
|
|
07bb05f337 | ||
|
|
ceeb2fc7cf | ||
|
|
1eccd58059 | ||
|
|
a82382eddf | ||
|
|
be6dbf4fe6 | ||
|
|
e898c7933c | ||
|
|
bce5b4df68 | ||
|
|
3810209ca6 | ||
|
|
39155bf63c | ||
|
|
93989a7ad1 | ||
|
|
8c6044b6a6 | ||
|
|
9c0c2c0bd1 | ||
|
|
380c09283d | ||
|
|
730b93d82a | ||
|
|
39d65d61c8 | ||
|
|
4ed844e0c5 | ||
|
|
1f2499a893 | ||
|
|
bca6853a4e | ||
|
|
0015cd23e4 | ||
|
|
8b5efdcdcc | ||
|
|
4bc24e66d4 | ||
|
|
53dcfa0087 | ||
|
|
c9755d4f64 | ||
|
|
6409ce4934 | ||
|
|
aa3a4a218c | ||
|
|
79fb3b76ca | ||
|
|
adb385a90b | ||
|
|
76b3014417 | ||
|
|
5fb1a440c4 | ||
|
|
4edee3e2d3 | ||
|
|
1a6800a7b4 | ||
|
|
95c9b12124 | ||
|
|
e11b80f80c | ||
|
|
d1e4f70188 | ||
|
|
8241b364cc | ||
|
|
706f32a972 | ||
|
|
c64304e632 | ||
|
|
c9cb88b9ef | ||
|
|
f177e8ae46 | ||
|
|
d4e9eb9b67 | ||
|
|
eb1fc6ef13 | ||
|
|
b698a2bfd3 | ||
|
|
3bd75e0799 | ||
|
|
404f19037e | ||
|
|
b02e3faef0 | ||
|
|
8b481ddd92 | ||
|
|
a599a02a14 | ||
|
|
84da6e065e | ||
|
|
15dee5cd1c | ||
|
|
87da25a8f2 | ||
|
|
20cd9b0964 | ||
|
|
560e1bb9bd | ||
|
|
d208306884 | ||
|
|
cd9ca28ba8 | ||
|
|
c2bf4db67a | ||
|
|
2783be37af | ||
|
|
ffe2fee88d | ||
|
|
5a1aa16e40 | ||
|
|
f75430fcc4 | ||
|
|
b515caf1e4 | ||
|
|
46b2a5ab1a | ||
|
|
3bccb896e2 | ||
|
|
dfb883e24c | ||
|
|
1ff72e4df4 | ||
|
|
01a89fd293 | ||
|
|
a1cef0866c | ||
|
|
24dea0821f | ||
|
|
20f1eb6e27 | ||
|
|
1bafafffc5 | ||
|
|
cc31bc6b84 | ||
|
|
76153bb524 | ||
|
|
dc33bee0e5 | ||
|
|
661b216359 | ||
|
|
e117f77a38 | ||
|
|
8dba1a4c5e | ||
|
|
b9b77840ab | ||
|
|
7791f088b9 | ||
|
|
c2babc3a39 | ||
|
|
a9f5fc45bd | ||
|
|
02a2d04441 | ||
|
|
d7fc0d2248 | ||
|
|
9f921ea7b5 | ||
|
|
66729b7337 | ||
|
|
a3082d0475 | ||
|
|
3868e0be35 | ||
|
|
40c98f4f04 | ||
|
|
032b6f5d0c | ||
|
|
b4c02a96d5 | ||
|
|
381395acaf | ||
|
|
cf39b64bfc | ||
|
|
c74b8372c0 | ||
|
|
41bb3f871e | ||
|
|
ff090d63f6 | ||
|
|
c5c6b3da06 | ||
|
|
6cee953edd | ||
|
|
afe2230ed9 | ||
|
|
5c5d7c7848 | ||
|
|
416e41cb00 | ||
|
|
7d4b6acacd | ||
|
|
dde913b922 |
4
.travis.yml
Normal file
4
.travis.yml
Normal file
@@ -0,0 +1,4 @@
|
||||
language: node_js
|
||||
sudo: false
|
||||
node_js:
|
||||
- "4.2"
|
||||
238
README.md
238
README.md
@@ -1,212 +1,74 @@
|
||||
## JPush PhoneGap Plugin ##
|
||||
# JPush PhoneGap / Cordova Plugin
|
||||
|
||||
jpush-phonegap-plugin 支持 iOS,Android 的推送插件。
|
||||
[](https://travis-ci.org/jpush/jpush-phonegap-plugin)
|
||||
[]()
|
||||
[](https://github.com/jpush/jpush-phonegap-plugin/releases)
|
||||
[](https://github.com/jpush/jpush-phonegap-plugin)
|
||||
[](http://weibo.com/jpush?refer_flag=1001030101_&is_all=1)
|
||||
|
||||
**功能特性:**
|
||||
>+ 发送推送通知
|
||||
+ 发送推送自定义消息
|
||||
+ 设置推送标签和别名
|
||||
+ 设置角标(iOS)
|
||||
支持 iOS, Android 的 Cordova 推送插件。
|
||||
> 如需要 IM 功能的插件,可关注 [JMessage PhoneGap Plugin](https://github.com/jpush/jmessage-phonegap-plugin)。
|
||||
|
||||
*如需要 IM 功能插件,请关注[jmessage-phonegap-plugin](https://github.com/jpush/jmessage-phonegap-plugin)*
|
||||
> 如需要短信验证码功能的插件,可关注 [JSMS Cordova Plugin](https://github.com/jpush/cordova-plugin-jsms)。
|
||||
|
||||
> QQ 交流群:413602425。
|
||||
|
||||
## 安装 ##
|
||||
###准备工作
|
||||
## Install
|
||||
|
||||
1. cordova create 文件夹名字 包名 应用名字
|
||||
- 通过 Cordova Plugins 安装,要求 Cordova CLI 5.0+:
|
||||
|
||||
cordova create Myproj com.myproj.jpush MyTestProj
|
||||
|
||||
2. 添加平台
|
||||
cordova plugin add jpush-phonegap-plugin --variable API_KEY=your_jpush_appkey
|
||||
|
||||
cd Myproj
|
||||
cordova platform add android
|
||||
cordova platform add ios
|
||||
- 或直接通过 url 安装:
|
||||
|
||||
ps:这里请注意iOS平台,必须先执行 `cordova platform add ios`,
|
||||
然后再执行`cordova plugin add xxxxx`命令,不然有一些必须要的链接库需要手动添加
|
||||
|
||||
cordova plugin add https://github.com/jpush/jpush-phonegap-plugin.git --variable API_KEY=your_jpush_appkey
|
||||
|
||||
###Cordova CLI/Phonegap 安装 Android & iOS
|
||||
- 或下载到本地安装:
|
||||
|
||||
1). 安装JPush PhoneGap Plugin。 有两种方法。
|
||||
cordova plugin add Your_Plugin_Path --variable API_KEY=your_jpush_appkey
|
||||
|
||||
方法一: 在线安装
|
||||
|
||||
cordova plugin add https://github.com/jpush/jpush-phonegap-plugin.git --variable API_KEY=your_jpush_appkey
|
||||
## Usage
|
||||
### API
|
||||
- [公共 API](/doc/Common_detail_api.md)
|
||||
- [iOS API](/doc/iOS_API.md)
|
||||
- [Android API](/doc/Android_detail_api.md)
|
||||
|
||||
方法二:下载到本地再安装
|
||||
### Demo
|
||||
插件项目中包含一个简单的 Demo。若想参考,可以在 */example* 文件夹内找到并拷贝以下文件:
|
||||
|
||||
使用git命令将jpush phonegap插件下载的本地,将这个目录标记为`$JPUSH_PLUGIN_DIR`
|
||||
example/index.html -> www/index.html
|
||||
example/css/* -> www/css
|
||||
example/js/* -> www/js
|
||||
|
||||
### 关于 PhoneGap build 云服务
|
||||
该项目基于 Cordova 实现,目前无法使用 PhoneGap build 云服务进行打包,建议使用本地环境进行打包。
|
||||
|
||||
git clone https://github.com/jpush/jpush-phonegap-plugin.git
|
||||
cordova plugin add $JPUSH_PLUGIN_DIR --variable API_KEY=your_jpush_appkey
|
||||
## FAQ
|
||||
> 如果遇到了疑问,请优先参考 Demo 和 API 文档。若还无法解决,可访问[极光社区](http://community.jiguang.cn/)或 [Issues](https://github.com/jpush/jpush-phonegap-plugin/issues) 提问。
|
||||
|
||||
### Android
|
||||
#### 在 Eclipse 中 import 工程之后出现:*Type CallbackContext cannot be resolved to a type*。
|
||||
右键单击工程名 -> Build Path -> Config Build Path -> Projects -> 选中工程名称 -> CordovaLib -> 点击 add。
|
||||
|
||||
### iOS
|
||||
#### PushConfig.plist 文件中的字段都是什么意思?
|
||||
- APP_KEY:应用标识。
|
||||
- CHANNEL:渠道标识。
|
||||
- IsProduction:是否生产环境。
|
||||
- IsIDFA:是否使用 IDFA 启动 SDK。
|
||||
|
||||
2). 安装org.apache.cordova.device
|
||||
#### 收不到推送了。
|
||||
请首先按照正确方式再次配置证书、描述文件,具体可参考 [iOS 证书设置指南](http://docs.jpush.io/client/ios_tutorials/#ios_1)。
|
||||
|
||||
cordova plugin add org.apache.cordova.device
|
||||
|
||||
## Support
|
||||
- QQ 群:413602425
|
||||
- [JPush 官网文档](http://docs.jpush.io/)
|
||||
- [极光社区](http://community.jiguang.cn/)
|
||||
|
||||
3). 在js中调用函数,初始化jpush sdk
|
||||
## Contribute
|
||||
Please contribute! [Look at the issues](https://github.com/jpush/jpush-phonegap-plugin/issues).
|
||||
|
||||
window.plugins.jPushPlugin.init();
|
||||
//由于phonegap插件采用了Lazy load的特性, 所以这里建议在js文件能执行的最开始就加
|
||||
|
||||
|
||||
### Android 手工安装
|
||||
|
||||
[Android 手工安装文档地址](document/Android_handle_install.md)
|
||||
|
||||
|
||||
### IOS手工安装
|
||||
|
||||
[IOS手工安装文档地址](document/iOS_handle_install.md)
|
||||
|
||||
|
||||
###示例
|
||||
|
||||
1. "$JPUSH_PLUGIN_DIR/example"文件夹内找到并拷贝以下文件
|
||||
|
||||
src/example/index.html to www/index.html
|
||||
src/example/css/* to www/css
|
||||
src/example/js/* to www/js
|
||||
|
||||
###关于'phonegap build'云服务
|
||||
|
||||
该项目基于cordova实现,目前无法使用'phonegap build'云服务进行打包,建议使用本地环境进行打包
|
||||
|
||||
### API说明
|
||||
|
||||
插件的API集中在JPushPlugin.js文件中,这个文件的位置如下
|
||||
|
||||
* android:[YOUR__ANDROID_PROJECT]/assets/www/plugins/cn.jpush.phonegap.JPushPlugin/www
|
||||
* iOS:[YOUR_iOS_PROJEcT]/www/plugins/cn.jpush.phonegap.JPushPlugin/www
|
||||
|
||||
具体的API请参考这里
|
||||
|
||||
#### iOS和adnroid通用API简介
|
||||
|
||||
+ 停止与恢复推送服务 API
|
||||
|
||||
window.plugins.jPushPlugin.init()
|
||||
window.plugins.jPushPlugin.stopPush()
|
||||
window.plugins.jPushPlugin.resumePush()
|
||||
window.plugins.jPushPlugin.isPushStopped(callback)
|
||||
|
||||
|
||||
+ 获取 RegistrationID API
|
||||
|
||||
window.plugins.jPushPlugin.getRegistrationID(callback)
|
||||
|
||||
+ 别名与标签 API
|
||||
|
||||
window.plugins.jPushPlugin.setTagsWithAlias(tags,alias)
|
||||
window.plugins.jPushPlugin.setTags(tags)
|
||||
window.plugins.jPushPlugin.setAlias(alias)
|
||||
+ 获取点击通知内容
|
||||
|
||||
event - jpush.openNotification
|
||||
+ 获取通知内容
|
||||
|
||||
event - jpush.receiveNotification
|
||||
|
||||
+ 获取自定义消息推送内容
|
||||
|
||||
event - jpush.receiveMessage
|
||||
|
||||
|
||||
[通用API详细说明](document/Common_detail_api.md)
|
||||
|
||||
#### iOS API简介
|
||||
|
||||
+ 获取自定义消息推送内容
|
||||
|
||||
event - jpush.receiveMessage
|
||||
//推荐使用事件的方式传递,但同时保留了receiveMessageIniOSCallback的回调函数,兼容以前的代码
|
||||
window.plugins.jPushPlugin.receiveMessageIniOSCallback(data)
|
||||
|
||||
+ 页面的统计
|
||||
|
||||
window.plugins.jPushPlugin.startLogPageView (pageName)
|
||||
window.plugins.jPushPlugin.stopLogPageView (pageName)
|
||||
window.plugins.jPushPlugin.beginLogPageView (pageName,duration)
|
||||
+ 设置Badge
|
||||
|
||||
window.plugins.jPushPlugin.setBadge(value)
|
||||
window.plugins.jPushPlugin.resetBadge()
|
||||
window.plugins.jPushPlugin.setApplicationIconBadgeNumber(badge)
|
||||
+ 本地通知
|
||||
|
||||
+ 后续版本加入
|
||||
|
||||
+ 日志等级设置
|
||||
|
||||
window.plugins.jPushPlugin.setDebugModeFromIos ()
|
||||
window.plugins.jPushPlugin.setLogOFF()
|
||||
|
||||
|
||||
[iOS API详细说明](document/iOS_detail_api.md)
|
||||
|
||||
|
||||
#### adnroid API简介
|
||||
|
||||
+ 获取集成日志
|
||||
window.plugins.jPushPlugin.setDebugMode(mode)
|
||||
|
||||
+ 接收推送消息和点击通知
|
||||
|
||||
//下面这两个api 是兼容旧有的代码
|
||||
window.plugins.jPushPlugin.receiveMessageInAndroidCallback(data)
|
||||
window.plugins.jPushPlugin.openNotificationInAndroidCallback(data)
|
||||
|
||||
+ 统计分析 API
|
||||
|
||||
onResume / onPause(java api)
|
||||
|
||||
+ 清除通知 API
|
||||
|
||||
window.plugins.jPushPlugin.clearAllNotification()
|
||||
|
||||
+ 通知栏样式定制 API
|
||||
|
||||
window.plugins.jPushPlugin.setBasicPushNotificationBuilder = function()
|
||||
window.plugins.jPushPlugin.setCustomPushNotificationBuilder = function()
|
||||
|
||||
+ 设置保留最近通知条数 API
|
||||
|
||||
window.plugins.jPushPlugin.setLatestNotificationNum(num)
|
||||
|
||||
+ 本地通知API
|
||||
|
||||
window.plugins.jPushPlugin.addLocalNotification(builderId,
|
||||
content,
|
||||
title,
|
||||
notificaitonID,
|
||||
broadcastTime,
|
||||
extras)
|
||||
window.plugins.jPushPlugin.removeLocalNotification(notificationID)
|
||||
window.plugins.jPushPlugin.clearLocalNotifications()
|
||||
|
||||
[Android API详细说明](document/Android_detail_api.md)
|
||||
|
||||
###常见问题
|
||||
|
||||
####1. androd
|
||||
|
||||
eclipse中phonegap工程import之后出现:`Type CallbackContext cannot be resolved to a type`
|
||||
解决方案:eclipse中右键单击工程名,Build Path->Config Build Path->Projects->选中 工程名称-CordovaLib->点击 add
|
||||
|
||||
####2. iOS 设置/修改 APP_KEY
|
||||
|
||||
在PushConfig.plist 中修改。PushConfig.plist 其他值说明:
|
||||
CHANNEL 渠道标识
|
||||
IsProduction 是否生产环境(暂未启用)
|
||||
|
||||
|
||||
|
||||
###更多
|
||||
[JPush官网文档](http://docs.jpush.io/)
|
||||
## License
|
||||
MIT © [JiGuang](/license)
|
||||
|
||||
324
doc/Android_detail_api.md
Normal file
324
doc/Android_detail_api.md
Normal file
@@ -0,0 +1,324 @@
|
||||
# Android API简介
|
||||
|
||||
- [接收通知时获得通知的内容](#接收通知时获得通知的内容)
|
||||
- [打开通知时获得通知的内容](#打开通知时获得通知的内容)
|
||||
- [收到自定义消息时获取消息的内容](#收到自定义消息时获取消息的内容)
|
||||
- [获取集成日志](#获取集成日志)
|
||||
- [接收消息和点击通知事件](#接收消息和点击通知事件)
|
||||
- [统计分析](#统计分析)
|
||||
- [清除通知](#清除通知)
|
||||
- [设置允许推送时间](#设置允许推送时间)
|
||||
- [设置通知静默时间](#设置通知静默时间)
|
||||
- [通知栏样式定制](#通知栏样式定制)
|
||||
- [设置保留最近通知条数](#设置保留最近通知条数)
|
||||
- [本地通知](#本地通知)
|
||||
- [富媒体页面 JavaScript 回调 API](#富媒体页面-javascript-回调-api)
|
||||
|
||||
## 接收通知时获得通知的内容
|
||||
|
||||
- 内容:
|
||||
window.plugins.jPushPlugin.receiveNotification.alert
|
||||
- 标题:
|
||||
window.plugins.jPushPlugin.receiveNotification.title
|
||||
- 附加字段:
|
||||
window.plugins.jPushPlugin.receiveNotification.extras.yourKey
|
||||
|
||||
## 打开通知时获得通知的内容
|
||||
|
||||
- 内容:
|
||||
window.plugins.jPushPlugin.openNotification.alert
|
||||
- 标题:
|
||||
window.plugins.jPushPlugin.openNotification.title
|
||||
- 附加字段
|
||||
window.plugins.jPushPlugin.openNotification.extras.yourKey
|
||||
|
||||
## 收到自定义消息时获取消息的内容
|
||||
|
||||
- 内容:
|
||||
window.plugins.jPushPlugin.receiveMessage.message
|
||||
- 附加字段:
|
||||
window.plugins.jPushPlugin.receiveMessage.extras.yourKey
|
||||
|
||||
## 获取集成日志
|
||||
|
||||
### API - setDebugMode
|
||||
|
||||
用于开启调试模式,可以查看集成 JPush 过程中的 Log,如果集成失败,可方便定位问题所在。
|
||||
|
||||
#### 接口定义
|
||||
|
||||
window.plugins.jPushPlugin.setDebugMode(mode)
|
||||
|
||||
#### 参数说明
|
||||
|
||||
- mode:
|
||||
- true 显示集成日志。
|
||||
- false 不显示集成日志。
|
||||
|
||||
|
||||
## 接收消息和点击通知事件
|
||||
### API - receiveMessageInAndroidCallback
|
||||
|
||||
用于 Android 收到应用内消息的回调函数(请注意和通知的区别),该函数不需要主动调用。
|
||||
|
||||
#### 接口定义
|
||||
|
||||
window.plugins.jPushPlugin.receiveMessageInAndroidCallback(data)
|
||||
|
||||
#### 参数说明
|
||||
|
||||
- data: 接收到的 js 字符串,包含的 key:value 请进入该函数体查看。
|
||||
|
||||
|
||||
### API - openNotificationInAndroidCallback
|
||||
|
||||
当点击 Android 手机的通知栏进入应用程序时,会调用这个函数,这个函数不需要主动调用,是作为回调函数来用的。
|
||||
|
||||
#### 接口定义
|
||||
|
||||
window.plugins.jPushPlugin.openNotificationInAndroidCallback(data)
|
||||
|
||||
#### 参数说明
|
||||
|
||||
- data: js 字符串。
|
||||
|
||||
|
||||
## 统计分析
|
||||
|
||||
### API - onResume / onPause
|
||||
|
||||
这是一个 Android Local API,不是 js 的 API,请注意。
|
||||
本 API 用于“用户使用时长”,“活跃用户”,“用户打开次数”的统计,并上报到服务器,在 Portal 上展示给开发者。
|
||||
|
||||
#### 接口定义
|
||||
|
||||
public static void onResume(final Activity activity)
|
||||
public static void onPause(final Activity activity)
|
||||
|
||||
#### 参数说明
|
||||
|
||||
- Activity: 当前所在的 Activity。
|
||||
|
||||
#### 调用说明
|
||||
|
||||
应在所有的 Activity 的 onResume / onPause 方法里调用。
|
||||
|
||||
#### 代码示例
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
JPushInterface.onResume(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPause() {
|
||||
super.onPause();
|
||||
JPushInterface.onPause(this);
|
||||
}
|
||||
|
||||
### API - setStatisticsOpen
|
||||
|
||||
用于在 js 中控制是否打开应用的统计分析功能,但如果已经添加了上面的 onResume / onPause 方法,
|
||||
就不能再通过这个方法来控制统计分析功能了。
|
||||
|
||||
#### 接口定义
|
||||
|
||||
window.plugins.jPushPlugin.setStatisticsOpen(boolean)
|
||||
|
||||
#### 参数说明
|
||||
|
||||
- boolean:
|
||||
- true: 打开统计分析功能。
|
||||
- false: 关闭统计分析功能。
|
||||
|
||||
### API - reportNotificationOpened
|
||||
|
||||
用于上报用户的通知栏被打开,或者用于上报用户自定义消息被展示等客户端需要统计的事件。
|
||||
|
||||
#### 接口定义
|
||||
|
||||
window.plugins.jPushPlugin.reportNotificationOpened(msgID)
|
||||
|
||||
#### 参数说明
|
||||
|
||||
- msgID: 收到的通知或者自定义消息的 id。
|
||||
|
||||
|
||||
## 清除通知
|
||||
|
||||
### API - clearAllNotification
|
||||
|
||||
推送通知到客户端时,由 JPush SDK 展现通知到通知栏上。
|
||||
|
||||
此 API 提供清除通知的功能,包括:清除所有 JPush 展现的通知(不包括非 JPush SDK 展现的)。
|
||||
|
||||
#### 接口定义
|
||||
|
||||
window.plugins.jPushPlugin.clearAllNotification()
|
||||
|
||||
|
||||
## 设置允许推送时间
|
||||
|
||||
### API - setPushTime
|
||||
默认情况下用户在任何时间都允许推送。即任何时候有推送下来,客户端都会收到,并展示。
|
||||
开发者可以调用此 API 来设置允许推送的时间。
|
||||
如果不在该时间段内收到消息,当前的行为是:推送到的通知会被扔掉。
|
||||
|
||||
#### 接口定义
|
||||
|
||||
window.plugins.jPushPlugin.setPushTime(days, startHour, endHour)
|
||||
|
||||
#### 参数说明
|
||||
- days: 数组,0 表示星期天,1 表示星期一,以此类推(7天制,数组中值的范围为 0 到 6 )。
|
||||
数组的值为 null, 表示任何时间都可以收到消息和通知,数组的 size 为 0,则表示任何时间都收不到消息和通知。
|
||||
- startHour: 整形,允许推送的开始时间 (24 小时制:startHour 的范围为 0 到 23)。
|
||||
- endHour: 整形,允许推送的结束时间 (24 小时制:endHour 的范围为 0 到 23)。
|
||||
|
||||
## 设置通知静默时间
|
||||
|
||||
### API - setSilenceTime
|
||||
默认情况下用户在收到推送通知时,客户端可能会有震动,响铃等提示。
|
||||
但用户在睡觉、开会等时间点希望为 "免打扰" 模式,也是静音时段的概念。
|
||||
开发者可以调用此 API 来设置静音时段。如果在该时间段内收到消息,则:不会有铃声和震动。
|
||||
|
||||
#### 接口定义
|
||||
|
||||
window.plugins.jPushPlugin.setSilenceTime(startHour, startMinute, endHour, endMinute)
|
||||
|
||||
#### 参数说明
|
||||
|
||||
- startHour: 整形,静音时段的开始时间 - 小时 (24小时制,范围:0~23 )。
|
||||
- startMinute: 整形,静音时段的开始时间 - 分钟(范围:0~59 )。
|
||||
- endHour: 整形,静音时段的结束时间 - 小时 (24小时制,范围:0~23 )。
|
||||
- endMinute: 整形,静音时段的结束时间 - 分钟(范围:0~59 )。
|
||||
|
||||
|
||||
## 通知栏样式定制
|
||||
|
||||
### API - setBasicPushNotificationBuilder, setCustomPushNotificationBuilder
|
||||
|
||||
当用户需要定制默认的通知栏样式时,则可调用此方法。
|
||||
需要用户去自定义 ../JPushPlugin.java 中的同名方法代码,然后再在 js 端 调用该方法。
|
||||
|
||||
具体用法可参考[官方文档](http://docs.jpush.io/client/android_tutorials/#_11)。
|
||||
|
||||
JPush SDK 提供了 2 个用于定制通知栏样式的构建类:
|
||||
|
||||
- setBasicPushNotificationBuilder:
|
||||
Basic 用于定制 Android Notification 里的 defaults / flags / icon 等基础样式(行为)。
|
||||
- setCustomPushNotificationBuilder:
|
||||
继承 Basic 进一步让开发者定制 Notification Layout。
|
||||
|
||||
如果不调用此方法定制,则极光 Push SDK 默认的通知栏样式是 Android 标准的通知栏。
|
||||
|
||||
#### 接口定义
|
||||
|
||||
window.plugins.jPushPlugin.setBasicPushNotificationBuilder()
|
||||
window.plugins.jPushPlugin.setCustomPushNotificationBuilder()
|
||||
|
||||
|
||||
## 设置保留最近通知条数
|
||||
|
||||
### API - setLatestNotificationNum
|
||||
|
||||
通过极光推送,推送了很多通知到客户端时,如果用户不去处理,就会有很多保留在那里。
|
||||
|
||||
默认为保留最近 5 条通知,开发者可通过调用此 API 来定义为不同的数量。
|
||||
|
||||
#### 接口定义
|
||||
|
||||
window.plugins.jPushPlugin.setLatestNotificationNum(num)
|
||||
|
||||
#### 参数说明
|
||||
|
||||
- num: 保存的条数。
|
||||
|
||||
|
||||
## 本地通知
|
||||
### API - addLocalNotification, removeLocalNotification, clearLocalNotifications
|
||||
|
||||
本地通知 API 不依赖于网络,无网条件下依旧可以触发。
|
||||
|
||||
本地通知与网络推送的通知是相互独立的,不受保留最近通知条数上限的限制。
|
||||
|
||||
本地通知的定时时间是自发送时算起的,不受中间关机等操作的影响。
|
||||
|
||||
三个接口的功能分别为:添加一个本地通知,删除一个本地通知,删除所有的本地通知。
|
||||
|
||||
#####接口定义
|
||||
|
||||
window.plugins.jPushPlugin.addLocalNotification(builderId, content, title,
|
||||
notificaitonID, broadcastTime, extras)
|
||||
window.plugins.jPushPlugin.removeLocalNotification(notificationID)
|
||||
window.plugins.jPushPlugin.clearLocalNotifications()
|
||||
|
||||
#### 参数说明
|
||||
|
||||
- builderId: 设置本地通知样式。
|
||||
- content: 设置本地通知的 content。
|
||||
- title: 设置本地通知的 title。
|
||||
- notificaitonID: 设置本地通知的 ID。
|
||||
- broadcastTime: 设置本地通知触发时间,为距离当前时间的数值,单位是毫秒。
|
||||
- extras: 设置额外的数据信息 extras 为 json 字符串。
|
||||
|
||||
|
||||
## 富媒体页面 JavaScript 回调 API
|
||||
富媒体推送通知时,用户可以用自定义的Javascript 函数来控制页面,如关闭当前页面,点击按钮跳转到指定的 Activity,通知应用程序做一些指定的动作等。
|
||||
|
||||
此 API 提供的回调函数包括:关闭当前页面、打开应用的主 Activity、根据 Activity 名字打开对应的 Activity、以广播的形式传递页面参数到应用程序等功能。
|
||||
|
||||
### API - 关闭当前页面
|
||||
|
||||
JPushWeb.close(); // 在富文本 HTML 页面中调用后会关闭当前页面。
|
||||
|
||||
### API - 打开主 Activity
|
||||
|
||||
JPushWeb.startMainActivity(String params);
|
||||
|
||||
在HTML中调用此函数后,会打开程序的主Activity, 并在对应的 Intent 传入参数 ”params“ ,Key 为 JPushInterface.EXTRA_EXTRA。
|
||||
|
||||
对应 Activity 获取 params 示例代码:
|
||||
|
||||
Intent intent = getIntent();
|
||||
if (null != intent ) {
|
||||
String params = intent.getStringExtra(JPushInterface.EXTRA_EXTRA);
|
||||
}
|
||||
|
||||
### API - 触发应用中的操作
|
||||
|
||||
JPushWeb.triggerNativeAction(String params);
|
||||
|
||||
调用了该方法后需要在 MyReceiver.java 中实现后面的业务逻辑:
|
||||
|
||||
if (JPushInterface.ACTION_RICHPUSH_CALLBACK.equals(intent.getAction())) {
|
||||
Log.d(TAG, "用户收到到RICH PUSH CALLBACK: " + bundle.getString(JPushInterface.EXTRA_EXTRA));
|
||||
//在这里根据 JPushInterface.EXTRA_EXTRA 的内容触发客户端动作,比如打开新的Activity 、打开一个网页等。
|
||||
}
|
||||
|
||||
#### 代码示例
|
||||
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
|
||||
<html>
|
||||
<head>
|
||||
<title>JPush Webview Test</title>
|
||||
<script>
|
||||
function clickButton() {
|
||||
JPushWeb.close();
|
||||
}
|
||||
|
||||
function openUrl() {
|
||||
var json = "{'action':'open', 'url':'www.jpush.cn'}";
|
||||
JPushWeb.triggerNativeAction(json);
|
||||
JPushWeb.close(); //客服端在广播中收到json 后,可以打开对应的URL。
|
||||
}
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<button onclick="javascript:clickButton(this);return false;">Close</button>
|
||||
<button onclick="javascript:JPushWeb.startMainActivity('test - startMainActivity');return false;">StartMainActivity</button>
|
||||
<button onclick="javascript:JPushWeb.triggerNativeAction('test - triggerNativeAction');Javascript:JPushWeb.close();">triggerNativeAction and Close current webwiew</button>
|
||||
<button onclick="javascript:JPushWeb.startActivityByName('com.example.jpushdemo.TestActivity','test - startActivityByName');">startActivityByName</button>
|
||||
<button onclick="javascript:openUrl();">open a url</button>
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,15 +1,23 @@
|
||||
#Android 手工安装
|
||||
#Android 手动安装
|
||||
|
||||
下载jpush phonegap插件,并解压缩,标记插件目录为:`$JPUSH_PLUGIN_DIR`
|
||||
下载 JPush PhoneGap 插件,并解压缩,标记插件目录为:`$JPUSH_PLUGIN_DIR`
|
||||
|
||||
1. 复制:`$JPUSH_PLUGIN_DIR`/src/android/*.java 到cn/jpush/phonega/目录下(即:cn.jpush.phonegap的包下)
|
||||
2. 复制:`$JPUSH_PLUGIN_DIR`/src/android/armeabi/libjpush.so 到lib/armeabi/
|
||||
3. 复制:`$JPUSH_PLUGIN_DIR`/src/android/jpush-sdk-release1.5.0.jar 到lib/
|
||||
4. 复制:`$JPUSH_PLUGIN_DIR`/src/android/test_notification_layout.xml到res/layout/
|
||||
5. 复制:`$JPUSH_PLUGIN_DIR`/src/android/jpush_notification_icon.png 到res/drawable/
|
||||
6. 修改 AndroidManifest.xml 在 manifest 节点下添加以下权限
|
||||
1. 复制:$JPUSH_PLUGIN_DIR/src/android/*.java 到 cn/jpush/phonega/ 目录下(即:cn.jpush.phonegap 的包下)
|
||||
2. 复制:$JPUSH_PLUGIN_DIR/src/android/armeabi/libjpush.so 到 lib/armeabi/
|
||||
3. 复制:$JPUSH_PLUGIN_DIR/src/android/jpush-sdk-release2.0.6.jar 到 lib/
|
||||
4. 复制:$JPUSH_PLUGIN_DIR/src/android/test_notification_layout.xml 到 res/layout/
|
||||
5. 复制:$JPUSH_PLUGIN_DIR/src/android/jpush_notification_icon.png 到 res/drawable/
|
||||
6. 复制:$JPUSH_PLUGIN_DIR/www/JPushPlugin.js 到 assets/www/plugins/cn.jpush.phonegap.JPushPlugin.www/
|
||||
和 platform_www/plugins/cn.jpush.phonegap.JPushPlugin/www/
|
||||
并在 JPushPlugin.js 文件的代码外添加:
|
||||
|
||||
<!-- Required 一些系统要求的权限,如访问网络等-->
|
||||
cordova.define("cn.jpush.phonegap.JPushPlugin.JPushPlugin", function(require, exports, module) {
|
||||
// 代码
|
||||
});
|
||||
|
||||
7. 修改 AndroidManifest.xml 在 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"/>
|
||||
@@ -25,24 +33,27 @@
|
||||
android:name="$PACKAGE_NAME.permission.JPUSH_MESSAGE"
|
||||
android:protectionLevel="signature"/>
|
||||
|
||||
7. 修改AndroidManifest.xml 在 manifest/application 节点下添加SDK相关组件声明
|
||||
7. 修改 AndroidManifest.xml 在 manifest/application 节点下添加SDK相关组件声明
|
||||
|
||||
<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>
|
||||
<!-- Required SDK核心功能-->
|
||||
|
||||
<!-- Required SDK 核心功能-->
|
||||
<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"
|
||||
@@ -53,22 +64,25 @@
|
||||
<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核心功能-->
|
||||
|
||||
<!-- Required SDK 核心功能-->
|
||||
<receiver
|
||||
android:name="cn.jpush.android.service.PushReceiver"
|
||||
android:enabled="true">
|
||||
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"/>
|
||||
|
||||
<!--Required 显示通知栏 -->
|
||||
<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"/>
|
||||
</intent-filter>
|
||||
|
||||
<!-- Optional -->
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.PACKAGE_ADDED"/>
|
||||
@@ -76,33 +90,46 @@
|
||||
<data android:scheme="package"/>
|
||||
</intent-filter>
|
||||
</receiver>
|
||||
|
||||
|
||||
<!-- User defined. For test only 用户自定义的广播接收器 -->
|
||||
<receiver
|
||||
android:name="cn.jpush.phonegap.MyReceiver"
|
||||
android:enabled="true">
|
||||
android:name="cn.jpush.phonegap.MyReceiver"
|
||||
android:enabled="true">
|
||||
<intent-filter android:priority="1000">
|
||||
<action android:name="cn.jpush.android.intent.NOTIFICATION_RECEIVED_PROXY"/>
|
||||
|
||||
<!-- Required 显示通知栏 -->
|
||||
<category android:name="$PACKAGE_NAME"/>
|
||||
</intent-filter>
|
||||
</intent-filter>
|
||||
|
||||
<intent-filter>
|
||||
<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"/>
|
||||
<!-- Required 用户接收SDK消息的intent -->
|
||||
<action android:name="cn.jpush.android.intent.NOTIFICATION_RECEIVED"/>
|
||||
<!-- Required 用户接收SDK通知栏信息的intent -->
|
||||
<action android:name="cn.jpush.android.intent.NOTIFICATION_OPENED"/>
|
||||
<!-- Required 用户打开自定义通知栏的intent -->
|
||||
<action android:name="cn.jpush.android.intent.ACTION_RICHPUSH_CALLBACK"/>
|
||||
<!-- Optional 用户接受Rich Push Javascript 回调函数的intent -->
|
||||
<category android:name="$PACKAGE_NAME"/>
|
||||
<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"/>
|
||||
|
||||
<!-- Required 用户接收 SDK 消息的intent -->
|
||||
<action android:name="cn.jpush.android.intent.NOTIFICATION_RECEIVED"/>
|
||||
|
||||
<!-- Required 用户接收 SDK 通知栏信息的intent -->
|
||||
<action android:name="cn.jpush.android.intent.NOTIFICATION_OPENED"/>
|
||||
|
||||
<!-- Required 用户打开自定义通知栏的intent -->
|
||||
<action android:name="cn.jpush.android.intent.ACTION_RICHPUSH_CALLBACK"/>
|
||||
|
||||
<!-- Optional 用户接受 Rich Push Javascript 回调函数的intent -->
|
||||
<category android:name="$PACKAGE_NAME"/>
|
||||
</intent-filter>
|
||||
</receiver>
|
||||
|
||||
<!-- Required SDK核心功能-->
|
||||
<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="299d0fee887820e7d90a68b2"/>
|
||||
<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="299d0fee887820e7d90a68b2"/>
|
||||
396
doc/Common_detail_api.md
Normal file
396
doc/Common_detail_api.md
Normal file
@@ -0,0 +1,396 @@
|
||||
# 通用 API 说明
|
||||
|
||||
- [停止与恢复推送服务](#停止与恢复推送服务)
|
||||
- [获取 RegistrationID](#获取-registrationid)
|
||||
- [设置别名与标签](#设置别名与标签)
|
||||
- [获取点击通知内容](#获取点击通知内容)
|
||||
- [获取通知内容](#获取通知内容)
|
||||
- [获取自定义消息推送内容](#获取自定义消息推送内容)
|
||||
- [判断系统设置中是否允许当前应用推送](#判断系统设置中是否允许当前应用推送)
|
||||
|
||||
## 停止与恢复推送服务
|
||||
### API - init
|
||||
|
||||
调用此 API,用来开启 JPush SDK 提供的推送服务。
|
||||
|
||||
开发者 App 可以通过调用停止推送服务 API 来停止极光推送服务。当又需要使用极光推送服务时,则必须要调用恢复推送服务 API。
|
||||
|
||||
本功能是一个完全本地的状态操作,也就是说:停止推送服务的状态不会保存到服务器上。
|
||||
|
||||
如果停止推送服务后,开发者 App 被重新安装,或者被清除数据,
|
||||
JPush SDK 会恢复正常的默认行为。(因为保存在本地的状态数据被清除掉了)。
|
||||
|
||||
本功能其行为类似于网络中断的效果,即:推送服务停止期间推送的消息,
|
||||
恢复推送服务后,如果推送的消息还在保留的时长范围内,则客户端是会收到离线消息。
|
||||
|
||||
#### 接口定义
|
||||
|
||||
window.plugins.jPushPlugin.init()
|
||||
|
||||
### API - stopPush
|
||||
+ Android 平台:
|
||||
|
||||
+ 开发者 App 可以通过调用停止推送服务 API 来停止极光推送服务,当又需要使用极光推送服务时,则必须要调用恢复推送服务 API。
|
||||
|
||||
+ 调用了本 API 后,JPush 推送服务完全被停止,具体表现为:
|
||||
|
||||
+ JPush Service 不在后台运行。
|
||||
+ 收不到推送消息。
|
||||
+ 不能通过 JPushInterface.init 恢复,需要调用 resumePush 恢复。
|
||||
+ 极光推送所有的其他 API 调用都无效。
|
||||
|
||||
+ iOS 平台:
|
||||
|
||||
+ 不推荐调用,因为这个 API 只是让你的 DeviceToken 失效,在 设置-通知 中您的应用程序没有任何变化。
|
||||
+ 推荐:设置一个 UI 界面, 提醒用户在 设置-通知 中关闭推送服务。
|
||||
|
||||
#### 接口定义
|
||||
|
||||
window.plugins.jPushPlugin.stopPush()
|
||||
|
||||
|
||||
### API - resumePush
|
||||
|
||||
恢复推送服务。调用了此 API 后:
|
||||
|
||||
+ Android 平台:
|
||||
|
||||
+ 极光推送完全恢复正常工作。
|
||||
|
||||
+ iOS 平台:
|
||||
|
||||
+ 重新去APNS注册。
|
||||
|
||||
#### 接口定义
|
||||
|
||||
window.plugins.jPushPlugin.resumePush()
|
||||
|
||||
### API - isPushStopped
|
||||
|
||||
+ Android 平台:
|
||||
|
||||
+ 用来检查 Push Service 是否已经被停止。
|
||||
|
||||
+ iOS 平台:
|
||||
|
||||
+ 平台检查推送服务是否注册。
|
||||
|
||||
|
||||
#### 接口定义
|
||||
|
||||
window.plugins.jPushPlugin.isPushStopped(callback)
|
||||
|
||||
#### 参数说明
|
||||
|
||||
+ callback: 回调函数,用来通知 JPush 的推送服务是否开启。
|
||||
|
||||
#### 代码示例
|
||||
|
||||
window.plugins.jPushPlugin.isPushStopped(function (result) {
|
||||
if (result == 0) {
|
||||
// 开启
|
||||
} else {
|
||||
// 关闭
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
## 获取 RegistrationID
|
||||
|
||||
### API - getRegistrationID
|
||||
|
||||
RegistrationID 定义:
|
||||
|
||||
集成了 JPush SDK 的应用程序在第一次成功注册到 JPush 服务器时,JPush 服务器会给客户端返回一个唯一的该设备的标识 - RegistrationID。
|
||||
JPush SDK 会以广播的形式发送 RegistrationID 到应用程序。
|
||||
|
||||
应用程序可以把此 RegistrationID 保存以自己的应用服务器上,然后就可以根据 RegistrationID 来向设备推送消息或者通知。
|
||||
|
||||
#### 接口定义
|
||||
|
||||
JPushPlugin.prototype.getRegistrationID(callback)
|
||||
|
||||
#### 返回值
|
||||
|
||||
调用此 API 来取得应用程序对应的 RegistrationID。 只有当应用程序成功注册到 JPush 的服务器时才返回对应的值,否则返回空字符串。
|
||||
|
||||
#### 代码示例
|
||||
|
||||
window.plugins.jPushPlugin.getRegistrationID(onGetRegistradionID);
|
||||
var onGetRegistradionID = function(data) {
|
||||
try {
|
||||
console.log("JPushPlugin:registrationID is " + data);
|
||||
} catch(exception) {
|
||||
console.log(exception);
|
||||
}
|
||||
}
|
||||
|
||||
## 设置别名与标签
|
||||
|
||||
### API - setTagsWithAlias, setTags, setAlias
|
||||
|
||||
提供几个相关 API 用来设置别名(alias)与标签(tags)。
|
||||
|
||||
这几个 API 可以在 App 里任何地方调用。
|
||||
|
||||
**别名 Alias**:
|
||||
|
||||
为安装了应用程序的用户,取个别名来标识。以后给该用户 Push 消息时,就可以用此别名来指定。
|
||||
|
||||
每个用户只能指定一个别名。
|
||||
|
||||
同一个应用程序内,对不同的用户,建议取不同的别名。这样,尽可能根据别名来唯一确定用户。
|
||||
|
||||
系统不限定一个别名只能指定一个用户。如果一个别名被指定到了多个用户,当给指定这个别名发消息时,服务器端 API 会同时给这多个用户发送消息。
|
||||
|
||||
举例:在一个用户要登录的游戏中,可能设置别名为 userid。游戏运营时,发现该用户 3 天没有玩游戏了,则根据 userid 调用服务器端 API 发通知到客户端提醒用户。
|
||||
|
||||
**标签 Tag**:
|
||||
|
||||
为安装了应用程序的用户,打上标签。其目的主要是方便开发者根据标签,来批量下发 Push 消息。
|
||||
|
||||
可为每个用户打多个标签。
|
||||
|
||||
不同应用程序、不同的用户,可以打同样的标签。
|
||||
|
||||
举例: game, old_page, women。
|
||||
|
||||
#### 接口定义
|
||||
|
||||
JPushPlugin.prototype.setTagsWithAlias(tags, alias)
|
||||
JPushPlugin.prototype.setTags(tags)
|
||||
JPushPlugin.prototype.setAlias(alias)
|
||||
|
||||
#### 参数说明
|
||||
* tags:
|
||||
* 参数类型为数组。
|
||||
* nil 此次调用不设置此值。
|
||||
* 空集合表示取消之前的设置。
|
||||
* 每次调用至少设置一个 tag,覆盖之前的设置,不是新增。
|
||||
* 有效的标签组成:字母(区分大小写)、数字、下划线、汉字。
|
||||
* 限制:每个 tag 命名长度限制为 40 字节,最多支持设置 100 个 tag,但总长度不得超过1K字节(判断长度需采用 UTF-8 编码)。
|
||||
* 单个设备最多支持设置 100 个 tag,App 全局 tag 数量无限制。
|
||||
* alias:
|
||||
* 参数类型为字符串。
|
||||
* nil 此次调用不设置此值。
|
||||
* 空字符串 ("")表示取消之前的设置。
|
||||
* 有效的别名组成:字母(区分大小写)、数字、下划线、汉字。
|
||||
* 限制:alias 命名长度限制为 40 字节(判断长度需采用 UTF-8 编码)。
|
||||
|
||||
#### 返回值说明
|
||||
|
||||
函数本身无返回值,但需要注册 `jpush.setTagsWithAlias` 事件来监听设置结果:
|
||||
|
||||
document.addEventListener("jpush.setTagsWithAlias", onTagsWithAlias, false);
|
||||
var onTagsWithAlias = function(event) {
|
||||
try {
|
||||
console.log("onTagsWithAlias");
|
||||
var result = "result code:" + event.resultCode + " ";
|
||||
result += "tags:" + event.tags + " ";
|
||||
result += "alias:" + event.alias + " ";
|
||||
$("#tagAliasResult").html(result);
|
||||
} catch(exception) {
|
||||
console.log(exception);
|
||||
}
|
||||
}
|
||||
|
||||
#### 错误码定义
|
||||
|
||||
|Code|描述 |详细解释 |
|
||||
|----|:----------------------------------------|:--------|
|
||||
|6001|无效的设置,tag / alias 不应参数都为 null。 | |
|
||||
|6002|设置超时。 |建议重试。|
|
||||
|6003|alias 字符串不合法。 |有效的别名、标签组成:字母(区分大小写)、数字、下划线、汉字。|
|
||||
|6004|alias超长。 |最多 40个字节,中文 UTF-8 是 3 个字节。|
|
||||
|6005|某一个 tag 字符串不合法。 |有效的别名、标签组成:字母(区分大小写)、数字、下划线、汉字。|
|
||||
|6006|某一个 tag 超长。 |一个 tag 最多 40个字节,中文 UTF-8 是 3 个字节。|
|
||||
|6007|tags 数量超出限制,最多 100 个。 |这是一台设备的限制,一个应用全局的标签数量无限制。|
|
||||
|6008|tag / alias 超出总长度限制。 |总长度最多 1K 字节。|
|
||||
|6011|10s内设置 tag 或 alias 大于 3 次。 |短时间内操作过于频繁。|
|
||||
|
||||
|
||||
## 获取点击通知内容
|
||||
|
||||
### event - jpush.openNotification
|
||||
|
||||
点击通知进入应用程序时会出发改事件。
|
||||
|
||||
#### 代码示例
|
||||
|
||||
- 在你需要接收通知的的 js 文件中加入:
|
||||
|
||||
document.addEventListener("jpush.openNotification", onOpenNotification, false);
|
||||
|
||||
- onOpenNotification 需要这样写:
|
||||
|
||||
var alertContent;
|
||||
if(device.platform == "Android") {
|
||||
alertContent = event.alert;
|
||||
} else {
|
||||
alertContent = event.aps.alert;
|
||||
}
|
||||
alert("open Notificaiton:" + alertContent);
|
||||
|
||||
ps:点击通知后传递的 json object 保存在 window.plugins.jPushPlugin.openNotification,直接访问即可,字段示例,根据实际推送情况,可能略有差别,请注意。
|
||||
|
||||
+ Android:
|
||||
|
||||
{
|
||||
"title": "title",
|
||||
"alert":"ding",
|
||||
"extras":{
|
||||
"yourKey": "yourValue",
|
||||
"cn.jpush.android.MSG_ID": "1691785879",
|
||||
"app": "com.thi.pushtest",
|
||||
"cn.jpush.android.ALERT": "ding",
|
||||
"cn.jpush.android.EXTRA": {},
|
||||
"cn.jpush.android.PUSH_ID": "1691785879",
|
||||
"cn.jpush.android.NOTIFICATION_ID": 1691785879,
|
||||
"cn.jpush.android.NOTIFICATION_TYPE": "0"
|
||||
}
|
||||
}
|
||||
|
||||
+ iOS:
|
||||
|
||||
{
|
||||
"aps":{
|
||||
"badge": 1,
|
||||
"sound": "default",
|
||||
"alert": "今天去哪儿"
|
||||
},
|
||||
"key1": "value1",
|
||||
"key2": "value2",
|
||||
"_j_msgid": 154604475
|
||||
}
|
||||
|
||||
## 获取通知内容
|
||||
|
||||
### event - jpush.receiveNotification
|
||||
|
||||
收到通知时会触发该事件。
|
||||
|
||||
#### 代码示例
|
||||
|
||||
- 在你需要接收通知的的 js 文件中加入:
|
||||
|
||||
document.addEventListener("jpush.receiveNotification", onReceiveNotification, false);
|
||||
|
||||
- onReceiveNotification 需要这样写:
|
||||
|
||||
var alertContent;
|
||||
if(device.platform == "Android") {
|
||||
alertContent = event.alert;
|
||||
} else {
|
||||
alertContent = event.aps.alert;
|
||||
}
|
||||
alert("open Notificaiton:" + alertContent);
|
||||
|
||||
ps:点击通知后传递的 json object 保存在 window.plugins.jPushPlugin.receiveNotification,直接访问即可,字段示例,根据实际推送情况,可能略有差别,请注意。
|
||||
|
||||
+ Android:
|
||||
|
||||
{
|
||||
"title": "title",
|
||||
"alert":"ding",
|
||||
"extras":{
|
||||
"yourKey": "yourValue",
|
||||
"cn.jpush.android.MSG_ID":"1691785879",
|
||||
"app":"com.thi.pushtest",
|
||||
"cn.jpush.android.ALERT":"ding",
|
||||
"cn.jpush.android.EXTRA":{},
|
||||
"cn.jpush.android.PUSH_ID":"1691785879",
|
||||
"cn.jpush.android.NOTIFICATION_ID":1691785879,
|
||||
"cn.jpush.android.NOTIFICATION_TYPE":"0"
|
||||
}
|
||||
}
|
||||
|
||||
+ iOS:
|
||||
|
||||
{
|
||||
"aps":{
|
||||
"badge":1,
|
||||
"sound":"default",
|
||||
"alert":"今天去哪儿"
|
||||
},
|
||||
"key1":"value1",
|
||||
"key2":"value2",
|
||||
"_j_msgid":154604475
|
||||
}
|
||||
|
||||
|
||||
## 获取自定义消息推送内容
|
||||
|
||||
### event - jpush.receiveMessage
|
||||
|
||||
收到自定义消息时触发这个事件,推荐使用事件的方式传递。
|
||||
|
||||
但同时保留了 receiveMessageIniOSCallback 的回调函数,兼容以前的代码。
|
||||
|
||||
#### 代码示例
|
||||
|
||||
- 在你需要接收通知的的 js 文件中加入:
|
||||
|
||||
document.addEventListener("jpush.receiveMessage", onReceiveMessage, false);
|
||||
|
||||
- onReceiveMessage 需要这样写:
|
||||
|
||||
var onReceiveMessage = function(event) {
|
||||
try{
|
||||
var message
|
||||
if(device.platform == "Android") {
|
||||
message = event.message;
|
||||
} else {
|
||||
message = event.content;
|
||||
}
|
||||
$("#messageResult").html(message);
|
||||
} catch(exception) {
|
||||
console.log("JPushPlugin:onReceiveMessage-->" + exception);
|
||||
}
|
||||
}
|
||||
|
||||
ps:点击通知后传递的 json object 保存在 window.plugins.jPushPlugin.receiveMessage,
|
||||
直接访问即可,字段示例,根据实际推送情况,可能略有差别,请注意。
|
||||
|
||||
+ Android:
|
||||
|
||||
{
|
||||
"message":"今天去哪儿",
|
||||
"extras"{
|
||||
"yourKey": "yourValue",
|
||||
"cn.jpush.android.MSG_ID":"154378013",
|
||||
"cn.jpush.android.CONTENT_TYPE":"",
|
||||
"cn.jpush.android.EXTRA":{"key":"不添没有"}
|
||||
}
|
||||
}
|
||||
|
||||
+ iOS:
|
||||
|
||||
{
|
||||
"content":"今天去哪儿",
|
||||
"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) {
|
||||
// 系统设置中打开了应用推送。
|
||||
}
|
||||
});
|
||||
571
doc/iOS_API.md
Normal file
571
doc/iOS_API.md
Normal file
@@ -0,0 +1,571 @@
|
||||
# iOS API
|
||||
|
||||
- [开始与停止推送服务](#开始与停止推送服务)
|
||||
- [获取 RegistrationID](#获取-registrationid)
|
||||
- [别名与标签](#别名与标签)
|
||||
- [获取 APNS 推送内容](#获取-apns-推送内容)
|
||||
- [点击推送通知](#点击推送通知)
|
||||
- [前台收到推送](#前台收到推送)
|
||||
- [后台收到推送](#后台收到推送)
|
||||
- [获取自定义消息内容](#获取自定义消息内容)
|
||||
- [设置Badge](#设置badge)
|
||||
- [本地通知](#本地通知)
|
||||
- [页面的统计](#页面的统计)
|
||||
- [日志等级设置](#日志等级设置)
|
||||
- [地理位置上报](#地理位置上报)
|
||||
- [设备平台判断](#设备平台判断)
|
||||
|
||||
## 开始与停止推送服务
|
||||
|
||||
### API - init
|
||||
|
||||
调用此 API,用来开启 JPush SDK 提供的推送服务。
|
||||
|
||||
开发者 App 可以通过调用停止推送服务 API 来停止极光推送服务,当又需要使用极光推送服务时,则必须要调用恢复推送服务 API。
|
||||
|
||||
```
|
||||
本功能是一个完全本地的状态操作。也就是说:停止推送服务的状态不会保存到服务器上。
|
||||
如果停止推送服务后,开发者 App 被重新安装,或者被清除数据,
|
||||
JPush SDK 会恢复正常的默认行为。(因为保存在本地的状态数据被清除掉了)。
|
||||
本功能其行为类似于网络中断的效果,即:推送服务停止期间推送的消息,
|
||||
恢复推送服务后,如果推送的消息还在保留的时长范围内,则客户端是会收到离线消息。
|
||||
```
|
||||
|
||||
#### 接口定义
|
||||
|
||||
window.plugins.jPushPlugin.init()
|
||||
|
||||
|
||||
### API - stopPush
|
||||
|
||||
- 不推荐调用,因为这个 API 只是让你的 DeviceToken 失效,在 设置-通知 中您的应用程序没有任何变化。
|
||||
- 推荐:设置一个 UI 界面,提醒用户在 设置-通知 中关闭推送服务。
|
||||
|
||||
#### 接口定义
|
||||
|
||||
window.plugins.jPushPlugin.stopPush()
|
||||
|
||||
|
||||
### API - resumePush
|
||||
|
||||
恢复推送服务。调用了此 API 后,iOS平台,重新去APNS注册。
|
||||
|
||||
#### 接口定义
|
||||
|
||||
window.plugins.jPushPlugin.resumePush()
|
||||
|
||||
|
||||
### API - isPushStopped
|
||||
|
||||
iOS平台,检查推送服务是否停止。
|
||||
|
||||
#### 接口定义
|
||||
|
||||
window.plugins.jPushPlugin.isPushStopped(callback)
|
||||
|
||||
|
||||
#### 参数说明
|
||||
|
||||
- callback 回调函数,用来通知 JPush 的推送服务是否开启。
|
||||
|
||||
#### 代码示例
|
||||
window.plugins.jPushPlugin.isPushStopped(callback)
|
||||
var callback = function(data) {
|
||||
if(data > 0) {
|
||||
// 已关闭
|
||||
} else {
|
||||
// 已开启
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
## 获取 RegistrationID
|
||||
|
||||
### API - getRegistrationID
|
||||
|
||||
RegistrationID 定义:
|
||||
|
||||
集成了 JPush SDK 的应用程序在第一次成功注册到 JPush 服务器时,JPush 服务器会给客户端返回一个唯一的该设备的标识 - RegistrationID。
|
||||
JPush SDK 会以广播的形式发送 RegistrationID 到应用程序。
|
||||
|
||||
应用程序可以把此 RegistrationID 保存以自己的应用服务器上,然后就可以根据 RegistrationID 来向设备推送消息或者通知。
|
||||
|
||||
#### 接口定义
|
||||
|
||||
JPushPlugin.prototype.getRegistrationID(callback)
|
||||
|
||||
#### 返回值
|
||||
|
||||
调用此 API 来取得应用程序对应的 RegistrationID。只有当应用程序成功注册到 JPush 的服务器时才返回对应的值,否则返回空字符串。
|
||||
|
||||
#### 调用示例
|
||||
|
||||
window.plugins.jPushPlugin.getRegistrationID(onGetRegistradionID);
|
||||
var onGetRegistradionID = function(data) {
|
||||
try {
|
||||
console.log("JPushPlugin:registrationID is " + data);
|
||||
} catch(exception) {
|
||||
console.log(exception);
|
||||
}
|
||||
}
|
||||
|
||||
## 别名与标签
|
||||
|
||||
### API - setTagsWithAlias, setTags, setAlias
|
||||
|
||||
提供几个相关 API 用来设置别名(alias)与标签(tags)。
|
||||
|
||||
这几个 API 可以在 App 里任何地方调用。
|
||||
|
||||
**别名 Alias**
|
||||
|
||||
为安装了应用程序的用户,取个别名来标识。以后给该用户 Push 消息时,就可以用此别名来指定。
|
||||
|
||||
每个用户只能指定一个别名。
|
||||
|
||||
同一个应用程序内,对不同的用户,建议取不同的别名。这样,尽可能根据别名来唯一确定用户。
|
||||
|
||||
系统不限定一个别名只能指定一个用户。如果一个别名被指定到了多个用户,当给指定这个别名发消息时,服务器端 API 会同时给这多个用户发送消息。
|
||||
|
||||
举例:在一个用户要登录的游戏中,可能设置别名为 userid。游戏运营时,发现该用户 3 天没有玩游戏了,则根据 userid 调用服务器端 API 发通知到客户端提醒用户。
|
||||
|
||||
**标签 Tag**
|
||||
|
||||
为安装了应用程序的用户,打上标签。其目的主要是方便开发者根据标签,来批量下发 Push 消息。
|
||||
|
||||
可为每个用户打多个标签。
|
||||
|
||||
不同应用程序、不同的用户,可以打同样的标签。
|
||||
|
||||
举例: game, old_page, women。
|
||||
|
||||
#### 接口定义
|
||||
|
||||
JPushPlugin.prototype.setTagsWithAlias(tags, alias)
|
||||
JPushPlugin.prototype.setTags(tags)
|
||||
JPushPlugin.prototype.setAlias(alias)
|
||||
|
||||
#### 参数说明
|
||||
* tags:
|
||||
* 参数类型为数组。
|
||||
* nil 此次调用不设置此值。
|
||||
* 空集合表示取消之前的设置。
|
||||
* 每次调用至少设置一个 tag,覆盖之前的设置,不是新增。
|
||||
* 有效的标签组成:字母(区分大小写)、数字、下划线、汉字。
|
||||
* 限制:每个 tag 命名长度限制为 40 字节,最多支持设置 100 个 tag,但总长度不得超过1K字节(判断长度需采用UTF-8编码)。
|
||||
* 单个设备最多支持设置 100 个 tag,App 全局 tag 数量无限制。
|
||||
* alias:
|
||||
* 参数类型为字符串。
|
||||
* nil 此次调用不设置此值。
|
||||
* 空字符串 ("")表示取消之前的设置。
|
||||
* 有效的别名组成:字母(区分大小写)、数字、下划线、汉字。
|
||||
* 限制:alias 命名长度限制为 40 字节(判断长度需采用 UTF-8 编码)。
|
||||
|
||||
#### 返回值说明
|
||||
|
||||
函数本身无返回值,但需要注册 `jpush.setTagsWithAlias` 事件来监听设置结果。
|
||||
|
||||
document.addEventListener("jpush.setTagsWithAlias", onTagsWithAlias, false);
|
||||
var onTagsWithAlias = function(event) {
|
||||
try {
|
||||
console.log("onTagsWithAlias");
|
||||
var result = "result code:"+event.resultCode + " ";
|
||||
result += "tags:" + event.tags + " ";
|
||||
result += "alias:" + event.alias + " ";
|
||||
$("#tagAliasResult").html(result);
|
||||
} catch(exception) {
|
||||
console.log(exception)
|
||||
}
|
||||
}
|
||||
|
||||
#### 错误码定义
|
||||
|
||||
|Code|描述 |详细解释 |
|
||||
|----|:----------------------------------------|:--------|
|
||||
|6001|无效的设置,tag/alias 不应参数都为 null | |
|
||||
|6002|设置超时 |建议重试。|
|
||||
|6003|alias 字符串不合法 |有效的别名、标签组成:字母(区分大小写)、数字、下划线、汉字。|
|
||||
|6004|alias超长 |最多 40个字节 中文 UTF-8 是 3 个字节。|
|
||||
|6005|某一个 tag 字符串不合法 |有效的别名、标签组成:字母(区分大小写)、数字、下划线、汉字。|
|
||||
|6006|某一个 tag 超长 |一个 tag 最多 40个字节 中文 UTF-8 是 3 个字节。|
|
||||
|6007|tags 数量超出限制(最多 100 个) |这是一台设备的限制。一个应用全局的标签数量无限制。|
|
||||
|6008|tag/alias 超出总长度限制 |总长度最多 1K 字节。|
|
||||
|6011|10s内设置tag或alias大于3次 |短时间内操作过于频繁。|
|
||||
|
||||
|
||||
## 获取 APNS 推送内容
|
||||
|
||||
### 点击推送通知
|
||||
|
||||
#### event - jpush.openNotification
|
||||
|
||||
点击通知启动或唤醒应用程序时会出发该事件
|
||||
|
||||
#### 代码示例
|
||||
|
||||
- 在你需要接收通知的的 js 文件中加入:
|
||||
|
||||
document.addEventListener("jpush.openNotification", onOpenNotification, false);
|
||||
|
||||
- onOpenNotification 需要这样写:
|
||||
|
||||
var onOpenNotification = function(event) {
|
||||
var alertContent;
|
||||
alertContent = event.aps.alert;
|
||||
alert("open Notificaiton:" + alertContent);
|
||||
}
|
||||
|
||||
- event 举例:
|
||||
|
||||
{
|
||||
"aps":{
|
||||
"badge":1,
|
||||
"sound":"default",
|
||||
"alert":"今天去哪儿"
|
||||
},
|
||||
"key1":"value1",
|
||||
"key2":"value2",
|
||||
"_j_msgid":154604475
|
||||
}
|
||||
|
||||
### 前台收到推送
|
||||
|
||||
#### event - jpush.receiveNotification
|
||||
|
||||
应用程序处于前台时收到推送会触发该事件
|
||||
|
||||
#### 代码示例
|
||||
|
||||
- 在你需要接收通知的的 js 文件中加入:
|
||||
|
||||
document.addEventListener("jpush.receiveNotification", onReceiveNotification, false);
|
||||
|
||||
- onReceiveNotification 需要这样写:
|
||||
|
||||
var onReceiveNotification = function(event) {
|
||||
var alertContent;
|
||||
alertContent = event.aps.alert;
|
||||
alert("open Notificaiton:" + alertContent);
|
||||
}
|
||||
|
||||
- event 举例
|
||||
|
||||
{
|
||||
"aps":{
|
||||
"badge":1,
|
||||
"sound":"default",
|
||||
"alert":"今天去哪儿"
|
||||
},
|
||||
"key1":"value1",
|
||||
"key2":"value2",
|
||||
"_j_msgid":154604475
|
||||
}
|
||||
|
||||
### 后台收到推送
|
||||
|
||||
#### event - jpush.backgroundNotification
|
||||
|
||||
应用程序处于后台时收到推送会触发该事件,可以在后台执行一段代码。具体配置参考 [iOS 7 Background Remote Notification](http://docs.jpush.io/client/ios_tutorials/#ios-7-background-remote-notification)
|
||||
|
||||
#### 代码示例
|
||||
|
||||
- 在你需要接收通知的的 js 文件中加入:
|
||||
|
||||
document.addEventListener("jpush.backgroundNotification", onBackgroundNotification, false);
|
||||
|
||||
- onBackgroundNotification 需要这样写:
|
||||
|
||||
var onBackgroundNotification = function(event) {
|
||||
var alertContent;
|
||||
alertContent = event.aps.alert;
|
||||
alert("open Notificaiton:" + alertContent);
|
||||
}
|
||||
|
||||
+ event 举例
|
||||
|
||||
{
|
||||
"aps":{
|
||||
"badge":1,
|
||||
"sound":"default",
|
||||
"alert":"今天去哪儿"
|
||||
},
|
||||
"key1":"value1",
|
||||
"key2":"value2",
|
||||
"_j_msgid":154604475
|
||||
}
|
||||
|
||||
#### API - receiveMessageIniOSCallback
|
||||
|
||||
用于 iOS 收到应用内消息的回调函数(请注意和通知的区别),该函数不需要主动调用
|
||||
不推荐使用回调函数
|
||||
|
||||
##### 接口定义
|
||||
|
||||
JPushPlugin.prototype.receiveMessageIniOSCallback(data)
|
||||
|
||||
##### 参数说明
|
||||
|
||||
- data: 是一个 js 字符串使用如下代码解析,js 具体 key 根据应用内消息来确定:
|
||||
|
||||
var bToObj = JSON.parse(data);
|
||||
|
||||
|
||||
## 获取自定义消息内容
|
||||
|
||||
|
||||
### event - jpush.receiveMessage
|
||||
|
||||
收到应用内消息时触发这个事件, 推荐使用事件的方式传递,但同时保留了 receiveMessageIniOSCallback 的回调函数,兼容以前的代码。
|
||||
|
||||
|
||||
#### 代码示例
|
||||
|
||||
- 在你需要接收通知的的 js 文件中加入:
|
||||
|
||||
document.addEventListener("jpush.receiveMessage", onReceiveMessage, false);
|
||||
|
||||
- onReceiveMessage 需要这样写:
|
||||
|
||||
var onReceiveMessage = function(event) {
|
||||
try{
|
||||
var message;
|
||||
message = event.content;
|
||||
$("#messageResult").html(message);
|
||||
}catch(exception) {
|
||||
console.log("JPushPlugin:onReceiveMessage-->" + exception);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
- event 举例:
|
||||
|
||||
{
|
||||
"content":"今天去哪儿",
|
||||
"extras":
|
||||
{
|
||||
"key":"不填写没有"
|
||||
}
|
||||
}
|
||||
|
||||
## 设置Badge
|
||||
### API - setBadge, resetBadge
|
||||
|
||||
JPush 封装 badge 功能,允许应用上传 badge 值至 JPush 服务器,
|
||||
由 JPush 后台帮助管理每个用户所对应的推送 badge 值,简化了设置推送 badge 的操作。
|
||||
(本接口不会直接改变应用本地的角标值. 要修改本地 badege 值,使用 setApplicationIconBadgeNumber)
|
||||
|
||||
实际应用中,开发者可以直接对 badge 值做增减操作,无需自己维护用户与 badge 值之间的对应关系。
|
||||
#### 接口定义
|
||||
|
||||
window.plugins.jPushPlugin.prototype.setBadge(value)
|
||||
window.plugins.jPushPlugin.prototype.reSetBadge()
|
||||
|
||||
resetBadge相当于setBadge(0)。
|
||||
|
||||
#### 参数说明
|
||||
value 取值范围:[0,99999]。
|
||||
|
||||
#### 返回值
|
||||
无,控制台会有 log 打印设置结果。
|
||||
|
||||
#### 代码示例
|
||||
|
||||
window.plugins.jPushPlugin.setBadge(5);
|
||||
window.plugins.jPushPlugin.reSetBadge();
|
||||
|
||||
### API - setApplicationIconBadgeNumber
|
||||
|
||||
本接口直接改变应用本地的角标值,设置 iOS 的角标,当设置 badge = 0 时为清除角标。
|
||||
|
||||
#### 接口定义
|
||||
|
||||
window.plugins.jPushPlugin.prototype.setApplicationIconBadgeNumber(badge)
|
||||
|
||||
#### 参数说明
|
||||
|
||||
- badge: 整形,例如 0,1,2(当 badge 为 0 时,角标被清除)。
|
||||
|
||||
#### 代码示例
|
||||
|
||||
window.plugins.jPushPlugin.setApplicationIconBadgeNumber(0);
|
||||
|
||||
### API - getApplicationIconBadgeNumber
|
||||
|
||||
获取 iOS 的角标值。
|
||||
|
||||
#### 接口定义
|
||||
|
||||
window.plugins.jPushPlugin.prototype.getApplicationIconBadgeNumber(callback)
|
||||
|
||||
#### 参数说明
|
||||
|
||||
- callback: 回调函数。
|
||||
|
||||
#### 代码示例
|
||||
|
||||
window.plugins.jPushPlugin.getApplicationIconBadgeNumber(function(data) {
|
||||
console.log(data);
|
||||
});
|
||||
|
||||
|
||||
## 本地通知
|
||||
|
||||
### API - addLocalNotificationForIOS
|
||||
|
||||
用于注册本地通知,最多支持64个。
|
||||
|
||||
#### 接口定义
|
||||
|
||||
window.plugins.jPushPlugin.prototype.addLocalNotificationForIOS(delayTime, content, badge, notificationID, extras)
|
||||
|
||||
#### 参数说明
|
||||
|
||||
- delayTime: 本地推送延迟多长时间后显示,数值类型或纯数字的字符型均可。
|
||||
- content: 本地推送需要显示的内容。
|
||||
- badge: 角标的数字。如果不需要改变角标传-1。数值类型或纯数字的字符型均可。
|
||||
- notificationID: 本地推送标识符,字符串。
|
||||
- extras: 自定义参数,可以用来标识推送和增加附加信息。字典类型。
|
||||
|
||||
#### 代码示例
|
||||
|
||||
window.plugins.jPushPlugin.addLocalNotificationForIOS(6*60*60, "本地推送内容", 1, "notiId", {"key":"value"});
|
||||
|
||||
### API - deleteLocalNotificationWithIdentifierKeyInIOS
|
||||
|
||||
删除本地推送定义。
|
||||
|
||||
#### 接口定义
|
||||
|
||||
window.plugins.jPushPlugin.prototype.deleteLocalNotificationWithIdentifierKeyInIOS(identifierKey)
|
||||
|
||||
#### 参数说明
|
||||
|
||||
- identifierKey: 本地推送标识符。
|
||||
|
||||
#### 代码示例
|
||||
|
||||
window.plugins.jPushPlugin.deleteLocalNotificationWithIdentifierKeyInIOS("identifier");
|
||||
|
||||
### API - clearAllLocalNotifications
|
||||
|
||||
清除所有本地推送对象。
|
||||
|
||||
#### 接口定义
|
||||
|
||||
window.plugins.jPushPlugin.prototype.clearAllLocalNotifications()
|
||||
|
||||
#### 代码示例
|
||||
|
||||
window.plugins.jPushPlugin.clearAllLocalNotifications();
|
||||
|
||||
|
||||
## 页面的统计
|
||||
|
||||
### API - startLogPageView, stopLogPageView, beginLogPageView
|
||||
|
||||
用于“用户指定页面使用时长”的统计,并上报到服务器,在 Portal 上展示给开发者。
|
||||
页面统计集成正确,才能够获取正确的页面访问路径、访问深度(PV)的数据。
|
||||
|
||||
#### 接口定义
|
||||
|
||||
window.plugins.jPushPlugin.prototype.startLogPageView(pageName)
|
||||
window.plugins.jPushPlugin.prototype.stopLogPageView(pageName)
|
||||
window.plugins.jPushPlugin.prototype.beginLogPageView(pageName, duration)
|
||||
|
||||
#### 参数说明
|
||||
|
||||
- pageName: 需要统计页面自定义名称
|
||||
- duration: 自定义的页面时间
|
||||
|
||||
#### 调用说明
|
||||
应在所有的需要统计得页面得 viewWillAppear 和 viewWillDisappear 加入 startLogPageView 和 stopLogPageView 来统计当前页面的停留时间。
|
||||
|
||||
或者直接使用 beginLogPageView 来自定义加入页面和时间信息。
|
||||
|
||||
#### 代码示例
|
||||
|
||||
window.plugins.jPushPlugin.beginLogPageView("newPage", 5);
|
||||
window.plugins.jPushPlugin.startLogPageView("onePage");
|
||||
window.plugins.jPushPlugin.stopLogPageView("onePage");
|
||||
|
||||
|
||||
## 日志等级设置
|
||||
|
||||
### API - setDebugModeFromIos
|
||||
|
||||
用于开启 Debug 模式,显示更多的日志信息。
|
||||
|
||||
建议调试时开启这个选项,不调试的时候注释这句代码,这个函数 setLogOFF 是相反的一对。
|
||||
|
||||
#### 接口定义
|
||||
|
||||
window.plugins.jPushPlugin.prototype.setDebugModeFromIos()
|
||||
|
||||
#### 代码示例
|
||||
|
||||
window.plugins.jPushPlugin.setDebugModeFromIos();
|
||||
|
||||
### API - setLogOFF
|
||||
|
||||
用来关闭日志信息(除了必要的错误信息)。
|
||||
|
||||
不需要任何调试信息的时候,调用此 API(发布时建议调用此 API,用来屏蔽日志信息,节省性能消耗)。
|
||||
|
||||
#### 接口定义
|
||||
|
||||
window.plugins.jPushPlugin.prototype.setLogOFF()
|
||||
|
||||
#### 代码示例
|
||||
|
||||
window.plugins.jPushPlugin.setLogOFF();
|
||||
|
||||
### API - setCrashLogON
|
||||
|
||||
用于统计用户应用崩溃日志。
|
||||
|
||||
如果需要统计 Log 信息,调用该接口。当你需要自己收集错误信息时,切记不要调用该接口。
|
||||
|
||||
#### 接口定义
|
||||
|
||||
window.plugins.jPushPlugin.prototype.setCrashLogON()
|
||||
|
||||
#### 代码示例
|
||||
|
||||
window.plugins.jPushPlugin.setCrashLogON();
|
||||
|
||||
## 地理位置上报
|
||||
|
||||
### API - setLocation
|
||||
|
||||
用于统计用户地理信息。
|
||||
|
||||
#### 接口定义
|
||||
|
||||
window.plugins.jPushPlugin.prototype.setLocation(latitude, longitude)
|
||||
|
||||
#### 参数说明
|
||||
|
||||
- latitude: 地理位置纬度,数值类型或纯数字的字符型均可。
|
||||
- longitude: 地理位置精度,数值类型或纯数字的字符型均可。
|
||||
|
||||
#### 代码示例
|
||||
|
||||
window.plugins.jPushPlugin.setLocation(39.26,115.25);
|
||||
|
||||
## 设备平台判断
|
||||
|
||||
### API - isPlatformIOS
|
||||
|
||||
用于区分 iOS, Android 平台,以便不同设置。
|
||||
|
||||
#### 接口定义
|
||||
|
||||
window.plugins.jPushPlugin.prototype.isPlatformIOS()
|
||||
|
||||
#### 代码示例
|
||||
|
||||
if(window.plugins.jPushPlugin.isPlatformIOS()) {
|
||||
// iOS
|
||||
} else {
|
||||
// Android
|
||||
}
|
||||
35
doc/iOS_install.md
Normal file
35
doc/iOS_install.md
Normal file
@@ -0,0 +1,35 @@
|
||||
## iOS 手动安装
|
||||
|
||||
- 下载 JPush PhoneGap Plugin 插件,并解压
|
||||
|
||||
- 将 [/src/ios](/src/ios) 文件夹及内容在 xcode 中拖到你的工程里,并配置 [/src/ios/PushConfig.plist](/src/ios/PushConfig.plist) 中相应参数:
|
||||
|
||||
APP_KEY: 应用标识
|
||||
CHANNEL: 渠道标识
|
||||
IsProduction:是否生产环境
|
||||
IsIDFA: 是否使用 IDFA 启动 sdk
|
||||
|
||||
- 打开 xcode,点击工程目录中顶部的 工程,选择(Target -> Build Phases -> Link Binary With Libraries),添加以下框架:
|
||||
|
||||
CFNetwork.framework
|
||||
CoreFoundation.framework
|
||||
CoreTelephony.framework
|
||||
SystemConfiguration.framework
|
||||
CoreGraphics.framework
|
||||
Foundation.framework
|
||||
UIKit.framework
|
||||
AdSupport.framework
|
||||
libz.tbd(若存在 libz.dylib 则替换为 libz.tbd)
|
||||
|
||||
- 修改 phonegap config.xml 文件以添加 JPushPlugin 插件
|
||||
|
||||
<feature name="JPushPlugin">
|
||||
<param name="ios-package" value="JPushPlugin" />
|
||||
<param name="onload" value="true" />
|
||||
</feature>
|
||||
|
||||
- 将 [/www/JPushPlugin.js](/www/JPushPlugin.js) 在 xcode 中拖到工程的 www 目录下面
|
||||
|
||||
- 在需要使用插件处加入以下代码,并根据 [iOS API](/doc/iOS_API.md) 文档说明调用相应接口
|
||||
|
||||
<script type="text/javascript" src="JPushPlugin.js"></script>
|
||||
@@ -1,185 +0,0 @@
|
||||
## adnroid API简介
|
||||
|
||||
|
||||
|
||||
### 获取集成日志
|
||||
|
||||
#### API - setDebugMode
|
||||
|
||||
用于开启调试模式,可以查看集成JPush过程中的log,如果集成失败,可方便定位问题所在
|
||||
|
||||
##### 接口定义
|
||||
|
||||
window.plugins.jPushPlugin.setDebugMode (mode)
|
||||
|
||||
##### 参数说明
|
||||
|
||||
- mode的值
|
||||
|
||||
- true 显示集成日志
|
||||
- false 不显示集成日志
|
||||
|
||||
|
||||
### 接收消息和点击通知事件
|
||||
#### API - receiveMessageInAndroidCallback
|
||||
|
||||
用于android收到应用内消息的回调函数(请注意和通知的区别),该函数不需要主动调用
|
||||
|
||||
##### 接口定义
|
||||
|
||||
window.plugins.jPushPlugin.receiveMessageInAndroidCallback = function(data)
|
||||
|
||||
##### 参数说明
|
||||
- data 接收到的js字符串,包含的key:value请进入该函数体查看
|
||||
|
||||
##### 代码示例
|
||||
|
||||
#### API - openNotificationInAndroidCallback
|
||||
|
||||
当点击android手机的通知栏进入应用程序时,会调用这个函数,这个函数不需要主动调用,是作为回调函数来用的
|
||||
|
||||
|
||||
##### 接口定义
|
||||
|
||||
window.plugins.jPushPlugin.openNotificationInAndroidCallback = function(data)
|
||||
|
||||
##### 参数说明
|
||||
- data js字符串
|
||||
|
||||
##### 代码示例
|
||||
|
||||
### 统计分析 API
|
||||
|
||||
#### API - onResume / onPause
|
||||
这是一个 android local api,不是js的api,请注意
|
||||
本 API 用于“用户使用时长”,“活跃用户”,“用户打开次数”的统计,并上报到服务器,在 Portal 上展示给开发者。
|
||||
|
||||
|
||||
|
||||
####接口定义
|
||||
|
||||
public static void onResume(final Activity activity)
|
||||
public static void onPause(final Activity activity)
|
||||
####参数说明
|
||||
|
||||
+ Activity activity 当前所在的Activity。
|
||||
####调用说明
|
||||
|
||||
应在所有的 Activity 的 onResume / onPause 方法里调用。
|
||||
|
||||
####代码示例
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
JPushInterface.onResume(this);
|
||||
}
|
||||
@Override
|
||||
protected void onPause() {
|
||||
super.onPause();
|
||||
JPushInterface.onPause(this);
|
||||
}
|
||||
|
||||
|
||||
#### API - reportNotificationOpened
|
||||
|
||||
用于上报用户的通知栏被打开,或者用于上报用户自定义消息被展示等客户端需要统计的事件。
|
||||
|
||||
|
||||
##### 接口定义
|
||||
|
||||
window.plugins.jPushPlugin.reportNotificationOpened(msgID)
|
||||
|
||||
##### 参数说明
|
||||
- msgID
|
||||
-收到的通知或者自定义消息的id
|
||||
|
||||
|
||||
### 清除通知 API
|
||||
|
||||
#### API - clearAllNotification
|
||||
|
||||
推送通知到客户端时,由 JPush SDK 展现通知到通知栏上。
|
||||
|
||||
此 API 提供清除通知的功能,包括:清除所有 JPush 展现的通知(不包括非 JPush SDK 展现的)
|
||||
|
||||
|
||||
##### 接口定义
|
||||
|
||||
window.plugins.jPushPlugin.clearAllNotification = function()
|
||||
|
||||
### 设置允许推送时间 API
|
||||
### 设置通知静默时间 API
|
||||
### 通知栏样式定制 API
|
||||
|
||||
#### API - setBasicPushNotificationBuilder,setCustomPushNotificationBuilder
|
||||
|
||||
当用户需要定制默认的通知栏样式时,则可调用此方法。
|
||||
极光 Push SDK 提供了 2 个用于定制通知栏样式的构建类:
|
||||
|
||||
- setBasicPushNotificationBuilder
|
||||
- Basic 用于定制 Android Notification 里的 defaults / flags / icon 等基础样式(行为)
|
||||
- setCustomPushNotificationBuilder
|
||||
- 继承 Basic 进一步让开发者定制 Notification Layout
|
||||
|
||||
如果不调用此方法定制,则极光Push SDK 默认的通知栏样式是:Android标准的通知栏提示。
|
||||
|
||||
##### 接口定义
|
||||
|
||||
window.plugins.jPushPlugin.setBasicPushNotificationBuilder = function()
|
||||
window.plugins.jPushPlugin.setCustomPushNotificationBuilder = function()
|
||||
|
||||
|
||||
### 设置保留最近通知条数 API
|
||||
|
||||
#### API - setLatestNotificationNum
|
||||
|
||||
通过极光推送,推送了很多通知到客户端时,如果用户不去处理,就会有很多保留在那里。
|
||||
|
||||
新版本 SDK (v1.3.0) 增加此功能,限制保留的通知条数。默认为保留最近 5 条通知。
|
||||
|
||||
开发者可通过调用此 API 来定义为不同的数量。
|
||||
|
||||
##### 接口定义
|
||||
|
||||
window.plugins.jPushPlugin.setLatestNotificationNum(num)
|
||||
|
||||
##### 参数说明
|
||||
|
||||
- num 保存的条数
|
||||
|
||||
|
||||
### 本地通知API
|
||||
#### API - addLocalNotification,removeLocalNotification,clearLocalNotifications
|
||||
|
||||
|
||||
本地通知API不依赖于网络,无网条件下依旧可以触发
|
||||
|
||||
本地通知与网络推送的通知是相互独立的,不受保留最近通知条数上限的限制
|
||||
|
||||
本地通知的定时时间是自发送时算起的,不受中间关机等操作的影响
|
||||
|
||||
|
||||
三个接口的功能分别为:添加一个本地通知,删除一个本地通知,删除所有的本地通知
|
||||
|
||||
#####接口定义
|
||||
|
||||
window.plugins.jPushPlugin.addLocalNotification = function(builderId,
|
||||
content,
|
||||
title,
|
||||
notificaitonID,
|
||||
broadcastTime,
|
||||
extras)
|
||||
window.plugins.jPushPlugin.removeLocalNotification = function(notificationID)
|
||||
window.plugins.jPushPlugin.clearLocalNotifications = function()
|
||||
|
||||
##### 参数说明
|
||||
|
||||
- builderId 设置本地通知样式
|
||||
- content 设置本地通知的content
|
||||
- title 设置本地通知的title
|
||||
- notificaitonID 设置本地通知的ID
|
||||
- broadcastTime 设置本地通知触发时间,为距离当前时间的数值,单位是毫秒
|
||||
- extras 设置额外的数据信息extras为json字符串
|
||||
|
||||
|
||||
@@ -1,375 +0,0 @@
|
||||
#通用API说明
|
||||
|
||||
|
||||
## 停止与恢复推送服务 API
|
||||
### API - init
|
||||
|
||||
调用此API,用来开启
|
||||
JPush SDK 提供的推送服务。
|
||||
|
||||
开发者App可以通过调用停止推送服务API来停止极光推送服务。当又需要使用极光推送服务时,则必须要调用恢复推送服务 API。
|
||||
|
||||
```
|
||||
本功能是一个完全本地的状态操作。也就是说:停止推送服务的状态不会保存到服务器上。
|
||||
|
||||
如果停止推送服务后,开发者App被重新安装,或者被清除数据,
|
||||
|
||||
JPush SDK 会恢复正常的默认行为。(因为保存在本地的状态数据被清除掉了)。
|
||||
本功能其行为类似于网络中断的效果,即:推送服务停止期间推送的消息,
|
||||
|
||||
恢复推送服务后,如果推送的消息还在保留的时长范围内,则客户端是会收到离线消息。
|
||||
```
|
||||
|
||||
#### 接口定义
|
||||
|
||||
window.plugins.jPushPlugin.init()
|
||||
|
||||
### API - stopPush
|
||||
+ 在android平台
|
||||
|
||||
+ 开发者App可以通过调用停止推送服务API来停止极光推送服务。当又需要使用极光推送服务时,则必须要调用恢复推送服务 API。
|
||||
|
||||
|
||||
+ 调用了本 API 后,JPush 推送服务完全被停止。具体表现为:
|
||||
|
||||
+ JPush Service 不在后台运行
|
||||
+ 收不到推送消息
|
||||
+ 不能通过 JPushInterface.init 恢复,需要调用resumePush恢复
|
||||
+ 极光推送所有的其他 API 调用都无效
|
||||
|
||||
+ iOS平台
|
||||
|
||||
+ 不推荐调用,因为这个API只是让你的DeviceToken失效,在设置-通知 中您的应用程序没有任何变化
|
||||
+ 推荐:设置一个UI界面, 提醒用户在在设置-通知关闭推送服务
|
||||
|
||||
### 接口定义
|
||||
|
||||
window.plugins.jPushPlugin.stopPush()
|
||||
|
||||
|
||||
#### API - resumePush
|
||||
|
||||
|
||||
恢复推送服务。调用了此 API 后
|
||||
|
||||
+ 在android平台
|
||||
|
||||
+ 极光推送完全恢复正常工作,
|
||||
|
||||
+ iOS平台
|
||||
|
||||
+ 重新去APNS注册
|
||||
|
||||
|
||||
|
||||
##### 接口定义
|
||||
|
||||
window.plugins.jPushPlugin.resumePush()
|
||||
|
||||
#### API - isPushStopped
|
||||
|
||||
+ 在android平台
|
||||
|
||||
+ 用来检查 Push Service 是否已经被停止
|
||||
|
||||
+ iOS平台
|
||||
|
||||
+ 平台检查推送服务是否注册
|
||||
|
||||
|
||||
##### 接口定义
|
||||
|
||||
window.plugins.jPushPlugin.isPushStopped(callback)
|
||||
|
||||
|
||||
##### 参数说明
|
||||
|
||||
+ callback 回调函数,用来通知JPush的推送服务是否开启
|
||||
|
||||
####代码示例
|
||||
window.plugins.jPushPlugin.resumePush(callback)
|
||||
var onCallback = function(data) {
|
||||
if(data>0){
|
||||
//开启
|
||||
}else{
|
||||
//关闭
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
##获取 RegistrationID API
|
||||
|
||||
### API - getRegistrationID
|
||||
|
||||
RegistrationID 定义
|
||||
|
||||
集成了 JPush SDK 的应用程序在第一次成功注册到 JPush 服务器时,JPush 服务器会给客户端返回一个唯一的该设备的标识 - RegistrationID。JPush SDK 会以广播的形式发送 RegistrationID 到应用程序。
|
||||
|
||||
应用程序可以把此 RegistrationID 保存以自己的应用服务器上,然后就可以根据 RegistrationID 来向设备推送消息或者通知。
|
||||
|
||||
#### 接口定义
|
||||
|
||||
JPushPlugin.prototype.getRegistrationID = function(callback)
|
||||
|
||||
##### 参数说明
|
||||
无
|
||||
#### 返回值
|
||||
|
||||
调用此 API 来取得应用程序对应的 RegistrationID。 只有当应用程序成功注册到 JPush 的服务器时才返回对应的值,否则返回空字符串。
|
||||
|
||||
#### 调用示例
|
||||
|
||||
window.plugins.jPushPlugin.getRegistrationID(onGetRegistradionID);
|
||||
var onGetRegistradionID = function(data) {
|
||||
try{
|
||||
console.log("JPushPlugin:registrationID is "+data) }
|
||||
catch(exception){
|
||||
console.log(exception);
|
||||
}
|
||||
}
|
||||
|
||||
##别名与标签 API
|
||||
|
||||
### API - setTagsWithAlias,setTags,setAlias
|
||||
|
||||
提供几个相关 API 用来设置别名(alias)与标签(tags)。
|
||||
|
||||
这几个 API 可以在 App 里任何地方调用。
|
||||
|
||||
别名 alias
|
||||
|
||||
为安装了应用程序的用户,取个别名来标识。以后给该用户 Push 消息时,就可以用此别名来指定。
|
||||
|
||||
每个用户只能指定一个别名。
|
||||
|
||||
同一个应用程序内,对不同的用户,建议取不同的别名。这样,尽可能根据别名来唯一确定用户。
|
||||
|
||||
系统不限定一个别名只能指定一个用户。如果一个别名被指定到了多个用户,当给指定这个别名发消息时,服务器端API会同时给这多个用户发送消息。
|
||||
|
||||
举例:在一个用户要登录的游戏中,可能设置别名为 userid。游戏运营时,发现该用户 3 天没有玩游戏了,则根据 userid 调用服务器端API发通知到客户端提醒用户。
|
||||
|
||||
标签 tag
|
||||
|
||||
为安装了应用程序的用户,打上标签。其目的主要是方便开发者根据标签,来批量下发 Push 消息。
|
||||
|
||||
可为每个用户打多个标签。
|
||||
|
||||
不同应用程序、不同的用户,可以打同样的标签。
|
||||
|
||||
举例: game, old_page, women
|
||||
|
||||
#### 接口定义
|
||||
|
||||
JPushPlugin.prototype.setTagsWithAlias = function(tags,alias)
|
||||
JPushPlugin.prototype.setTags = function(tags)
|
||||
JPushPlugin.prototype.setAlias = function(alias)
|
||||
|
||||
####使用平台
|
||||
android iOS
|
||||
|
||||
|
||||
#### 参数说明
|
||||
* tags
|
||||
* 参数类型为数组
|
||||
* nil 此次调用不设置此值
|
||||
* 空集合表示取消之前的设置
|
||||
* 每次调用至少设置一个 tag,覆盖之前的设置,不是新增
|
||||
* 有效的标签组成:字母(区分大小写)、数字、下划线、汉字
|
||||
* 限制:每个 tag 命名长度限制为 40 字节,最多支持设置 100 个 tag,但总长度不得超过1K字节。(判断长度需采用UTF-8编码)
|
||||
* 单个设备最多支持设置 100 个 tag。App 全局 tag 数量无限制。
|
||||
* alias
|
||||
* 参数类型为字符串
|
||||
* nil 此次调用不设置此值
|
||||
* 空字符串 ("")表示取消之前的设置
|
||||
* 有效的别名组成:字母(区分大小写)、数字、下划线、汉字。
|
||||
* 限制:alias 命名长度限制为 40 字节。(判断长度需采用UTF-8编码)
|
||||
|
||||
#### 返回值说明
|
||||
|
||||
函数本身无返回值,但需要注册`jpush.setTagsWithAlias `事件来监听设置结果
|
||||
|
||||
document.addEventListener("jpush.setTagsWithAlias", onTagsWithAlias, false);
|
||||
var onTagsWithAlias = function(event){
|
||||
try{
|
||||
console.log("onTagsWithAlias");
|
||||
var result="result code:"+event.resultCode+" ";
|
||||
result+="tags:"+event.tags+" ";
|
||||
result+="alias:"+event.alias+" ";
|
||||
$("#tagAliasResult").html(result);
|
||||
}
|
||||
catch(exception){
|
||||
console.log(exception)
|
||||
}
|
||||
}
|
||||
|
||||
####错误码定义
|
||||
|
||||
|
||||
|
||||
|
||||
|Code|描述|详细解释|
|
||||
|-|-|-|
|
||||
|6001| 无效的设置,tag/alias 不应参数都为 null||
|
||||
|6002| 设置超时| 建议重试|
|
||||
|6003| alias| 字符串不合法 有效的别名、标签组成:字母(区分大小写)、数字、下划线、汉字。|
|
||||
|6004| alias超长。最多 40个字节 中文 UTF-8 是 3 个字节|
|
||||
|6005| 某一个 tag 字符串不合法| 有效的别名、标签组成:字母(区分大小写)、数字、下划线、汉字。|
|
||||
|6006| 某一个 tag 超长。|一个 tag 最多 40个字节 中文 UTF-8 是 3 个字节|
|
||||
|6007| tags 数量超出限制。最多 100个| 这是一台设备的限制。一个应用全局的标签数量无限制。|
|
||||
|6008| tag/alias 超出总长度限制。|总长度最多 1K 字节|
|
||||
|6011| 10s内设置tag或alias大于3次| 短时间内操作过于频繁|
|
||||
|
||||
### 获取点击通知内容
|
||||
|
||||
#### event - jpush.openNotification
|
||||
|
||||
点击通知进入应用程序时会出发改事件
|
||||
|
||||
#####代码示例
|
||||
|
||||
- 在你需要接收通知的的js文件中加入:
|
||||
|
||||
document.addEventListener("jpush.openNotification", onOpenNotification, false);
|
||||
|
||||
- onOpenNotification需要这样写:
|
||||
|
||||
|
||||
var alertContent
|
||||
if(device.platform == "Android"){
|
||||
alertContent=window.plugins.jPushPlugin.openNotification.alert;
|
||||
}else{
|
||||
alertContent = event.aps.alert;
|
||||
}
|
||||
alert("open Notificaiton:"+alertContent);
|
||||
|
||||
ps:点击通知后传递的json object 保存在window.plugins.jPushPlugin.openNotification,直接访问即可,字段示例,根据实际推送情况,可能略有差别,请注意
|
||||
|
||||
+ android
|
||||
|
||||
{"alert":"ding",
|
||||
"extras":{
|
||||
"cn.jpush.android.MSG_ID":"1691785879",
|
||||
"app":"com.thi.pushtest",
|
||||
"cn.jpush.android.ALERT":"ding",
|
||||
"cn.jpush.android.EXTRA":{},
|
||||
"cn.jpush.android.PUSH_ID":"1691785879",
|
||||
"cn.jpush.android.NOTIFICATION_ID":1691785879,
|
||||
"cn.jpush.android.NOTIFICATION_TYPE":"0"}}
|
||||
|
||||
+ iOS
|
||||
|
||||
{
|
||||
"aps":{
|
||||
"badge":1,
|
||||
"sound":"default",
|
||||
"alert":"今天去哪儿"
|
||||
},
|
||||
"_j_msgid":154604475
|
||||
}
|
||||
|
||||
### 获取通知内容
|
||||
|
||||
#### event - jpush.receiveNotification
|
||||
|
||||
点击通知进入应用程序时会触发该事件
|
||||
|
||||
#####代码示例
|
||||
|
||||
- 在你需要接收通知的的js文件中加入:
|
||||
|
||||
document.addEventListener("jpush.receiveNotification", onReceiveNotification, false);
|
||||
|
||||
- onReceiveNotification需要这样写:
|
||||
|
||||
|
||||
var alertContent
|
||||
if(device.platform == "Android"){
|
||||
alertContent=window.plugins.jPushPlugin.receiveNotification.alert;
|
||||
}else{
|
||||
alertContent = event.aps.alert;
|
||||
}
|
||||
alert("open Notificaiton:"+alertContent);
|
||||
|
||||
ps:点击通知后传递的json object 保存在window.plugins.jPushPlugin.receiveNotification,直接访问即可,字段示例,根据实际推送情况,可能略有差别,请注意
|
||||
|
||||
+ android
|
||||
|
||||
{"alert":"ding",
|
||||
"extras":{
|
||||
"cn.jpush.android.MSG_ID":"1691785879",
|
||||
"app":"com.thi.pushtest",
|
||||
"cn.jpush.android.ALERT":"ding",
|
||||
"cn.jpush.android.EXTRA":{},
|
||||
"cn.jpush.android.PUSH_ID":"1691785879",
|
||||
"cn.jpush.android.NOTIFICATION_ID":1691785879,
|
||||
"cn.jpush.android.NOTIFICATION_TYPE":"0"}}
|
||||
|
||||
+ iOS
|
||||
|
||||
{
|
||||
"aps":{
|
||||
"badge":1,
|
||||
"sound":"default",
|
||||
"alert":"今天去哪儿"
|
||||
},
|
||||
"_j_msgid":154604475
|
||||
}
|
||||
|
||||
|
||||
### 获取自定义消息推送内容
|
||||
|
||||
|
||||
####event - jpush.receiveMessage
|
||||
|
||||
收到应用内消息时触发这个事件
|
||||
|
||||
`推荐使用事件的方式传递,但同时保留了receiveMessageIniOSCallback的回调函数,兼容以前的代码`
|
||||
|
||||
|
||||
#####代码示例
|
||||
|
||||
- 在你需要接收通知的的js文件中加入:
|
||||
|
||||
document.addEventListener("jpush.receiveMessage", onReceiveMessage, false);
|
||||
|
||||
- onReceiveMessage需要这样写:
|
||||
|
||||
|
||||
var onReceiveMessage = function(event){
|
||||
try{
|
||||
var message
|
||||
if(device.platform == "Android"){
|
||||
message = window.plugins.jPushPlugin.receiveMessage.message;
|
||||
}else{
|
||||
message = event.content;
|
||||
}
|
||||
$("#messageResult").html(message);
|
||||
|
||||
}
|
||||
catch(exception){
|
||||
console.log("JPushPlugin:onReceiveMessage-->"+exception);
|
||||
}
|
||||
}
|
||||
|
||||
ps:点击通知后传递的json object 保存在window.plugins.jPushPlugin.receiveMessage,直接访问即可,字段示例,根据实际推送情况,可能略有差别,请注意
|
||||
|
||||
+ android
|
||||
|
||||
{"message":"今天去哪儿",
|
||||
"extras"{
|
||||
"cn.jpush.android.MSG_ID":"154378013",
|
||||
"cn.jpush.android.CONTENT_TYPE":"",
|
||||
"cn.jpush.android.EXTRA":{"key":"不添没有"}
|
||||
}
|
||||
}
|
||||
+ iOS
|
||||
|
||||
{
|
||||
"content":"今天去哪儿",
|
||||
"extras":
|
||||
{
|
||||
"key":"不填写没有"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,150 +0,0 @@
|
||||
## iOS API简介
|
||||
|
||||
### 获取 APNs(通知) 推送内容
|
||||
|
||||
|
||||
#### API - receiveMessageIniOSCallback
|
||||
|
||||
用于iOS收到应用内消息的回调函数(请注意和通知的区别),该函数不需要主动调用
|
||||
不推荐使用回调函数
|
||||
|
||||
##### 接口定义
|
||||
|
||||
JPushPlugin.prototype.receiveMessageIniOSCallback = function(data)
|
||||
|
||||
#####参数说明
|
||||
|
||||
- data 是一个js字符串使用如下代码解析,js具体key根据应用内消息来确定
|
||||
|
||||
var bToObj = JSON.parse(data);
|
||||
|
||||
#####返回值
|
||||
无
|
||||
|
||||
##### 代码示例
|
||||
|
||||
|
||||
### 页面的统计
|
||||
#### API - startLogPageView,stopLogPageView,beginLogPageView
|
||||
|
||||
本 API 用于“用户指定页面使用时长”的统计,并上报到服务器,在 Portal 上展示给开发者。页面统计集成正确,才能够获取正确的页面访问路径、访问深度(PV)的数据。
|
||||
|
||||
##### 接口定义
|
||||
window.plugins.jPushPlugin.startLogPageView = function(pageName)
|
||||
window.plugins.jPushPlugin.stopLogPageView = function(pageName)
|
||||
window.plugins.jPushPlugin.beginLogPageView = function(pageName,duration)
|
||||
#####参数说明
|
||||
pageName 需要统计页面自定义名称
|
||||
duration 自定义的页面时间
|
||||
#####调用说明
|
||||
应在所有的需要统计得页面得 viewWillAppear 和 viewWillDisappear 加入 startLogPageView 和 stopLogPageView 来统计当前页面的停留时间。
|
||||
|
||||
或者直接使用 beginLogPageView 来自定义加入页面和时间信息。
|
||||
#####返回值说明
|
||||
无
|
||||
#####代码示例
|
||||
|
||||
if(window.plugins.jPushPlugin.isPlatformIOS()){
|
||||
window.plugins.jPushPlugin.beginLogPageView("newPage",5);
|
||||
window.plugins.jPushPlugin.startLogPageView("onePage");
|
||||
window.plugins.jPushPlugin.stopLogPageView("onePage");
|
||||
}
|
||||
### 设置Badge
|
||||
#### API - setBadge,resetBadge
|
||||
|
||||
JPush封装badge功能,允许应用上传badge值至JPush服务器,由JPush后台帮助管理每个用户所对应的推送badge值,简化了设置推送badge的操作。
|
||||
(本接口不会直接改变应用本地的角标值. 要修改本地badege值,使用 setApplicationIconBadgeNumber)
|
||||
|
||||
实际应用中,开发者可以直接对badge值做增减操作,无需自己维护用户与badge值之间的对应关系。
|
||||
##### 接口定义
|
||||
|
||||
window.plugins.jPushPlugin.setBadge(value)
|
||||
window.plugins.jPushPlugin.reSetBadge()
|
||||
|
||||
`resetBadge相当于setBadge(0)`
|
||||
##### 参数说明
|
||||
value 取值范围:[0,99999]
|
||||
##### 返回值
|
||||
无,控制台会有log打印设置结果
|
||||
#####代码示例
|
||||
|
||||
if(window.plugins.jPushPlugin.isPlatformIOS()){
|
||||
window.plugins.jPushPlugin.setBadge(5);
|
||||
window.plugins.jPushPlugin.reSetBadge();
|
||||
}
|
||||
|
||||
#### API - setApplicationIconBadgeNumber
|
||||
|
||||
本接口直接改变应用本地的角标值.
|
||||
设置iOS的角标,当设置badge=0时为清除角标
|
||||
|
||||
##### 接口定义
|
||||
|
||||
window.plugins.jPushPlugin.setApplicationIconBadgeNumber(badge)
|
||||
|
||||
##### 参数说明
|
||||
|
||||
- badge 整形,例如0,1,2
|
||||
- 当badge为0时,角标被清除
|
||||
|
||||
#####代码示例
|
||||
|
||||
if(window.plugins.jPushPlugin.isPlatformIOS()){
|
||||
window.plugins.jPushPlugin.setApplicationIconBadgeNumber(0);
|
||||
}
|
||||
|
||||
|
||||
#### API - getApplicationIconBadgeNumber
|
||||
|
||||
获取iOS的角标值
|
||||
|
||||
##### 接口定义
|
||||
|
||||
window.plugins.jPushPlugin.getApplicationIconBadgeNumber(callback)
|
||||
|
||||
##### 参数说明
|
||||
|
||||
- callback 回调函数
|
||||
|
||||
#####代码示例
|
||||
```
|
||||
|
||||
window.plugins.jPushPlugin.getApplicationIconBadgeNumber(function(data){
|
||||
console.log(data);
|
||||
});
|
||||
|
||||
```
|
||||
|
||||
### 本地通知
|
||||
|
||||
### 日志等级设置
|
||||
#### API - setDebugModeFromIos
|
||||
API 用于开启Debug模式,显示更多的日志信息
|
||||
|
||||
建议调试时开启这个选项,不调试的时候注释这句代码,这个函数setLogOFF是相反的一对
|
||||
##### 接口定义
|
||||
|
||||
window.plugins.jPushPlugin.reSetBadge.setDebugModeFromIos()
|
||||
|
||||
#####代码示例
|
||||
|
||||
if(window.plugins.jPushPlugin.isPlatformIOS()){
|
||||
window.plugins.jPushPlugin.setDebugModeFromIos();
|
||||
}
|
||||
|
||||
#### API - setLogOFF
|
||||
|
||||
API用来关闭日志信息(除了必要的错误信息)
|
||||
|
||||
不需要任何调试信息的时候,调用此API (发布时建议调用此API,用来屏蔽日志信息,节省性能消耗)
|
||||
|
||||
##### 接口定义
|
||||
|
||||
window.plugins.jPushPlugin.reSetBadge.setLogOFF ()
|
||||
|
||||
#####代码示例
|
||||
|
||||
if(window.plugins.jPushPlugin.isPlatformIOS()){
|
||||
window.plugins.jPushPlugin.setLogOFF();
|
||||
}
|
||||
|
||||
@@ -1,62 +0,0 @@
|
||||
### IOS手工安装
|
||||
|
||||
下载jpush phonegap插件,并解压缩,标记插件目录为:`$JPUSH_PLUGIN_DIR`
|
||||
|
||||
|
||||
1. 用xcode打开iOS工程 将`$JPUSH_PLUGIN_DIR`/src/ios/Plugins/拖到project中
|
||||
2. 将`$JPUSH_PLUGIN_DIR`/src/ios/lib/拖到project中
|
||||
|
||||
4. 添加以下框架,打开xocode,点击project,选择(Target -> Build Phases -> Link Binary With Libraries)
|
||||
|
||||
CFNetwork.framework
|
||||
CoreFoundation.framework
|
||||
CoreTelephony.framework
|
||||
SystemConfiguration.framework
|
||||
CoreGraphics.framework
|
||||
Foundation.framework
|
||||
UIKit.framework
|
||||
|
||||
|
||||
5. 在你的工程中创建一个新的Property List文件
|
||||
|
||||
并将其命名为PushConfig.plist,填入Portal为你的应用提供的APP_KEY等参数
|
||||
|
||||
10. 在AppDelegate.m中包含头文件
|
||||
|
||||
#import "APService.h"
|
||||
#import "JPushPlugin.h"
|
||||
|
||||
6. 调用代码,监听系统事件,相应地调用 JPush SDK 提供的 API 来实现功能
|
||||
|
||||
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{
|
||||
//原内容保持不变
|
||||
//Required add
|
||||
[JPushPlugin setLaunchOptions:launchOptions];
|
||||
return YES;
|
||||
}
|
||||
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
|
||||
//原内容保持不变
|
||||
// Required add
|
||||
[APService registerDeviceToken:deviceToken];
|
||||
}
|
||||
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
|
||||
//原内容保持不变
|
||||
// Required
|
||||
[APService handleRemoteNotification:userInfo];
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:kJPushPluginReceiveNotification
|
||||
object:userInfo];
|
||||
}
|
||||
|
||||
7. 修改phonegap config.xml文件用来包含Plugin/内的插件
|
||||
|
||||
|
||||
<feature name="JPushPlugin">
|
||||
<param name="ios-package" value="JPushPlugin" />
|
||||
<param name="onload" value="true" />
|
||||
</feature>
|
||||
|
||||
|
||||
8. 复制`$JPUSH_PLUGIN_DIR`/www/PushNotification.js到工程的www目录下面
|
||||
9. 在需要使用插件处加入
|
||||
|
||||
<script type="text/javascript" src="JPushPlugin.js"></script>
|
||||
BIN
example/.DS_Store
vendored
BIN
example/.DS_Store
vendored
Binary file not shown.
@@ -3,222 +3,196 @@
|
||||
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
||||
<title>Phonegap Sample App</title>
|
||||
<link href="css/jquery.mobile-1.1.1.css" rel="stylesheet" type="text/css"/>
|
||||
<title>JPush Phonegap Simple Demo</title>
|
||||
<link href="css/jquery.mobile-1.1.1.css" rel="stylesheet" type="text/css" />
|
||||
<script type="text/javascript" src="js/jquery.js"></script>
|
||||
<script type="text/javascript" src="js/jquery.mobile-1.1.1.js"></script>
|
||||
<script type="text/javascript" src="cordova.js"></script>
|
||||
<script type="text/javascript">
|
||||
var onDeviceReady = function () {
|
||||
var onDeviceReady = function() {
|
||||
console.log("JPushPlugin:Device ready!");
|
||||
initiateUI();
|
||||
};
|
||||
|
||||
function getRegistrationID() {
|
||||
window.plugins.jPushPlugin.getRegistrationID(onGetRegistradionID);
|
||||
}
|
||||
var getRegistrationID = function() {
|
||||
window.plugins.jPushPlugin.getRegistrationID(onGetRegistrationID);
|
||||
};
|
||||
|
||||
var onGetRegistradionID = function (data) {
|
||||
var onGetRegistrationID = function(data) {
|
||||
try {
|
||||
|
||||
console.log("JPushPlugin:registrationID is " + data);
|
||||
|
||||
if (data.length == 0) {
|
||||
var t1 = window.setTimeout(getRegistrationID, 1000);
|
||||
}
|
||||
$("#registrationid").html(data);
|
||||
}
|
||||
catch (exception) {
|
||||
$("#registrationId").html(data);
|
||||
} catch (exception) {
|
||||
console.log(exception);
|
||||
}
|
||||
};
|
||||
|
||||
var onTagsWithAlias = function (event) {
|
||||
var onTagsWithAlias = function(event) {
|
||||
try {
|
||||
console.log("onTagsWithAlias");
|
||||
var result = "result code:" + event.resultCode + " ";
|
||||
result += "tags:" + event.tags + " ";
|
||||
result += "alias:" + event.alias + " ";
|
||||
$("#tagAliasResult").html(result);
|
||||
}
|
||||
catch (exception) {
|
||||
} catch (exception) {
|
||||
console.log(exception)
|
||||
}
|
||||
};
|
||||
var onOpenNotification = function (event) {
|
||||
|
||||
var onOpenNotification = function(event) {
|
||||
try {
|
||||
var alertContent;
|
||||
if (device.platform == "Android") {
|
||||
alertContent = window.plugins.jPushPlugin.openNotification.alert;
|
||||
alertContent = event.alert;
|
||||
} else {
|
||||
alertContent = event.aps.alert;
|
||||
}
|
||||
alert("open Notificaiton:" + alertContent);
|
||||
|
||||
}
|
||||
catch (exception) {
|
||||
alert("open Notification:" + alertContent);
|
||||
} catch (exception) {
|
||||
console.log("JPushPlugin:onOpenNotification" + exception);
|
||||
}
|
||||
};
|
||||
var onReceiveNotification = function (event) {
|
||||
|
||||
var onReceiveNotification = function(event) {
|
||||
try {
|
||||
var alertContent;
|
||||
if (device.platform == "Android") {
|
||||
alertContent = window.plugins.jPushPlugin.receiveNotification.alert;
|
||||
alertContent = event.alert;
|
||||
} else {
|
||||
alertContent = event.aps.alert;
|
||||
}
|
||||
$("#notificationResult").html(alertContent);
|
||||
|
||||
}
|
||||
catch (exeption) {
|
||||
} catch (exception) {
|
||||
console.log(exception)
|
||||
}
|
||||
};
|
||||
var onReceiveMessage = function (event) {
|
||||
try {
|
||||
|
||||
var onReceiveMessage = function(event) {
|
||||
try {
|
||||
var message;
|
||||
if (device.platform == "Android") {
|
||||
message = window.plugins.jPushPlugin.receiveMessage.message;
|
||||
message = event.message;
|
||||
} else {
|
||||
message = event.content;
|
||||
}
|
||||
//var extras = window.plugins.jPushPlugin.extras
|
||||
|
||||
$("#messageResult").html(message);
|
||||
|
||||
}
|
||||
catch (exception) {
|
||||
} catch (exception) {
|
||||
console.log("JPushPlugin:onReceiveMessage-->" + exception);
|
||||
}
|
||||
};
|
||||
|
||||
var initiateUI = function () {
|
||||
|
||||
var initiateUI = function() {
|
||||
try {
|
||||
window.plugins.jPushPlugin.init();
|
||||
getRegistrationID();
|
||||
|
||||
if (device.platform != "Android") {
|
||||
window.plugins.jPushPlugin.setDebugModeFromIos();
|
||||
window.plugins.jPushPlugin.setApplicationIconBadgeNumber(0);
|
||||
} else {
|
||||
window.plugins.jPushPlugin.setDebugMode(true);
|
||||
window.plugins.jPushPlugin.setStatisticsOpen(true);
|
||||
}
|
||||
}
|
||||
catch (exception) {
|
||||
} catch (exception) {
|
||||
console.log(exception);
|
||||
}
|
||||
$("#setTagWithAliasButton").click(function (ev) {
|
||||
|
||||
// window.plugins.jPushPlugin.getApplicationIconBadgeNumber(function(data){
|
||||
// console.log(data);
|
||||
// });
|
||||
|
||||
$("#setTagWithAliasButton").click(function(ev) {
|
||||
try {
|
||||
var tag1 = $("#tagText1").attr("value");
|
||||
var tag2 = $("#tagText2").attr("value");
|
||||
var tag3 = $("#tagText3").attr("value");
|
||||
var alias = $("#aliasText").attr("value");
|
||||
var dd = [];
|
||||
var tags = [];
|
||||
|
||||
if (tag1 == "" && tag2 == "" && tag3 == "") {
|
||||
if (tag1 != "") {
|
||||
tags.push(tag1);
|
||||
}
|
||||
else {
|
||||
if (tag1 != "") {
|
||||
dd.push(tag1);
|
||||
}
|
||||
if (tag2 != "") {
|
||||
dd.push(tag2);
|
||||
}
|
||||
if (tag3 != "") {
|
||||
dd.push(tag3);
|
||||
}
|
||||
if (tag2 != "") {
|
||||
tags.push(tag2);
|
||||
}
|
||||
window.plugins.jPushPlugin.setTagsWithAlias(dd, alias);
|
||||
|
||||
}
|
||||
catch (exception) {
|
||||
if (tag3 != "") {
|
||||
tags.push(tag3);
|
||||
}
|
||||
window.plugins.jPushPlugin.setTagsWithAlias(tags, alias);
|
||||
} catch (exception) {
|
||||
console.log(exception);
|
||||
}
|
||||
})
|
||||
};
|
||||
|
||||
document.addEventListener("jpush.setTagsWithAlias", onTagsWithAlias, false);
|
||||
document.addEventListener("deviceready", onDeviceReady, false);
|
||||
document.addEventListener("jpush.openNotification", onOpenNotification, false);
|
||||
document.addEventListener("jpush.receiveNotification", onReceiveNotification, false);
|
||||
document.addEventListener("jpush.receiveMessage", onReceiveMessage, false);
|
||||
|
||||
|
||||
//jpush.receiveMessage
|
||||
</script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div data-role="page" id="page">
|
||||
|
||||
<div data-role="content">
|
||||
<form>
|
||||
<div class="ui-body ui-body-b">
|
||||
|
||||
<div data-role="fieldcontain">
|
||||
<center><h3>JPushPlugin Example</h3></center>
|
||||
<span name="alias" id="alias"></span>
|
||||
<hr/>
|
||||
<label>RegistrationID: </label>
|
||||
<label id="registrationid">null</label>
|
||||
<div data-role="page" id="page">
|
||||
<div data-role="content">
|
||||
<form>
|
||||
<div class="ui-body ui-body-b">
|
||||
<div data-role="fieldcontain">
|
||||
<center>
|
||||
<h3>JPushPlugin Example</h3>
|
||||
</center>
|
||||
<span name="alias" id="alias"></span>
|
||||
<hr/>
|
||||
<label>RegistrationID: </label>
|
||||
<label id="registrationId">null</label>
|
||||
</div>
|
||||
<div data-role="fieldcontain">
|
||||
<label>Tags: </label>
|
||||
<table>
|
||||
<tr>
|
||||
<td>
|
||||
<input type="text" id="tagText1" />
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<input type="text" id="tagText2" />
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<input type="text" id="tagText3" />
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<label>Alias: </label>
|
||||
<table>
|
||||
<tr>
|
||||
<td>
|
||||
<input type="text" id="aliasText" />
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
<div data-role="fieldcontain">
|
||||
<input type="button" id="setTagWithAliasButton"
|
||||
value="Add tag and alias" />
|
||||
</div>
|
||||
<div data-role="fieldcontain">
|
||||
<label id="tagAliasPrompt">设置tag/alias结果:</label>
|
||||
<label id="tagAliasResult">null</label>
|
||||
</div>
|
||||
<div data-role="fieldcontain">
|
||||
<label id="notificationPrompt">接受的通知内容:</label>
|
||||
<label id="notificationResult">null</label>
|
||||
</div>
|
||||
<div data-role="fieldcontain">
|
||||
<label id="messagePrompt">接受的自定义消息:</label>
|
||||
<label id="messageResult">null</label>
|
||||
</div>
|
||||
</div>
|
||||
<div data-role="fieldcontain">
|
||||
<label>Tags: </label>
|
||||
<table>
|
||||
<tr>
|
||||
<td>
|
||||
<input type="text" id="tagText1"/>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<input type="text" id="tagText2"/>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<input type="text" id="tagText3">
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<label>Alias: </label>
|
||||
<table>
|
||||
<tr>
|
||||
<td>
|
||||
<input type="text" id="aliasText">
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
<div data-role="fieldcontain">
|
||||
<input type="button" id="setTagWithAliasButton" value="Add tag and alias"/>
|
||||
</div>
|
||||
<div data-role="fieldcontain">
|
||||
<label id="tagAliasPrompt">设置tag/alias结果: </label>
|
||||
<label id="tagAliasResult">null</label>
|
||||
</div>
|
||||
<div data-role="fieldcontain">
|
||||
<label id="notificationPrompt">接受的通知内容:</label>
|
||||
<label id="notificationResult">null</label>
|
||||
</div>
|
||||
<div data-role="fieldcontain">
|
||||
<label id="messagePrompt">接受的自定义消息:</label>
|
||||
<label id="messageResult">null</label>
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
</form>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
|
||||
|
||||
|
||||
21
license
Normal file
21
license
Normal 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.
|
||||
39
package.json
Normal file
39
package.json
Normal file
@@ -0,0 +1,39 @@
|
||||
{
|
||||
"name": "jpush-phonegap-plugin",
|
||||
"version": "2.2.6",
|
||||
"description": "JPush for cordova plugin",
|
||||
"cordova": {
|
||||
"id": "jpush-phonegap-plugin",
|
||||
"platforms": [
|
||||
"ios",
|
||||
"android"
|
||||
]
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/jpush/jpush-phonegap-plugin.git"
|
||||
},
|
||||
"keywords": [
|
||||
"JPush",
|
||||
"push",
|
||||
"Push",
|
||||
"ecosystem:cordova",
|
||||
"cordova-ios",
|
||||
"cordova-android"
|
||||
],
|
||||
"engines": [
|
||||
{
|
||||
"name": "cordova",
|
||||
"version": ">=3.0"
|
||||
}
|
||||
],
|
||||
"peerDependencies": {
|
||||
"cordova-plugin-device": ">=1.0.0"
|
||||
},
|
||||
"author": "JiGuang",
|
||||
"license": "MIT",
|
||||
"bugs": {
|
||||
"url": "https://github.com/jpush/jpush-phonegap-plugin/issues"
|
||||
},
|
||||
"homepage": "https://github.com/jpush/jpush-phonegap-plugin#readme"
|
||||
}
|
||||
242
plugin.xml
242
plugin.xml
@@ -1,176 +1,192 @@
|
||||
<?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="cn.jpush.phonegap.JPushPlugin"
|
||||
version="2.1.0">
|
||||
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>
|
||||
|
||||
<!-- dependencies -->
|
||||
<dependency id="cordova-plugin-device" />
|
||||
|
||||
<js-module src="www/JPushPlugin.js" name="JPushPlugin">
|
||||
<clobbers target="jPushPlugin"/>
|
||||
<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/lib/JPUSHService.h" />
|
||||
<source-file src="src/ios/lib/jpush-ios-2.1.0.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.dylib" weak="true" />
|
||||
<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.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>
|
||||
|
||||
<!-- 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="/*">
|
||||
<feature name="JPushPlugin">
|
||||
<param name="android-package" value="cn.jpush.phonegap.JPushPlugin"/>
|
||||
<param name="android-package" value="cn.jpush.phonegap.JPushPlugin" />
|
||||
</feature>
|
||||
</config-file>
|
||||
|
||||
<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>
|
||||
<!-- Required SDK核心功能-->
|
||||
<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">
|
||||
<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"/>
|
||||
|
||||
<!-- Rich push 核心功能 since 2.0.6-->
|
||||
<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>
|
||||
|
||||
<!-- Required SDK 核心功能-->
|
||||
<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" />
|
||||
</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"/>
|
||||
<data android:scheme="package"/>
|
||||
<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>
|
||||
<action android:name="cn.jpush.android.intent.DaemonService" />
|
||||
<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"/>
|
||||
<!-- 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"/>
|
||||
<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" />
|
||||
</config-file>
|
||||
<source-file src="src/android/jpush-android-2.0.6.jar" target-dir="libs"/>
|
||||
<source-file src="src/android/armeabi/libjpush206.so" target-dir="libs/armeabi"/>
|
||||
<source-file src="src/android/armeabi-v7a/libjpush206.so" target-dir="libs/armeabi-v7a"/>
|
||||
<source-file src="src/android/arm64-v8a/libjpush206.so" target-dir="libs/arm64-v8a"/>
|
||||
|
||||
<!--<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/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-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" />
|
||||
|
||||
<!-- Rich Push resources -->
|
||||
<source-file src="src/android/ic_richpush_actionbar_back.png" target-dir="res/drawable" />
|
||||
<source-file src="src/android/ic_richpush_actionbar_divider.png" target-dir="res/drawable" />
|
||||
<source-file src="src/android/richpush_btn_selector.xml" target-dir="res/drawable" />
|
||||
<source-file src="src/android/jpush_popwin_layout.xml" target-dir="res/layout" />
|
||||
<source-file src="src/android/jpush_webview_layout.xml" target-dir="res/layout" />
|
||||
<source-file src="src/android/jpush_style.xml" target-dir="res/values" />
|
||||
|
||||
</platform>
|
||||
</plugin>
|
||||
|
||||
@@ -1,48 +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-lib/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);
|
||||
});
|
||||
}
|
||||
};
|
||||
File diff suppressed because it is too large
Load Diff
@@ -12,82 +12,92 @@ import android.content.Intent;
|
||||
import android.util.Log;
|
||||
|
||||
public class MyReceiver extends BroadcastReceiver {
|
||||
private static String TAG = "JPushPlugin";
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
private static String TAG = "JPushPlugin";
|
||||
private static final List<String> IGNORED_EXTRAS_KEYS =
|
||||
Arrays.asList(
|
||||
"cn.jpush.android.TITLE",
|
||||
"cn.jpush.android.MESSAGE",
|
||||
"cn.jpush.android.APPKEY",
|
||||
"cn.jpush.android.NOTIFICATION_CONTENT_TITLE"
|
||||
);
|
||||
|
||||
if (JPushInterface.ACTION_REGISTRATION_ID.equals(intent.getAction())) {
|
||||
|
||||
// }else if (JPushInterface.ACTION_UNREGISTER.equals(intent.getAction())){
|
||||
|
||||
} else if (JPushInterface.ACTION_MESSAGE_RECEIVED.equals(intent.getAction())) {
|
||||
handlingReceivedMessage(intent);
|
||||
} else if (JPushInterface.ACTION_NOTIFICATION_RECEIVED.equals(intent.getAction())) {
|
||||
handlingNotificationReceive(context,intent);
|
||||
|
||||
} else if (JPushInterface.ACTION_NOTIFICATION_OPENED.equals(intent.getAction())) {
|
||||
handlingNotificationOpen(context,intent);
|
||||
} else if (JPushInterface.ACTION_RICHPUSH_CALLBACK.equals(intent.getAction())) {
|
||||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
String action = intent.getAction();
|
||||
if (JPushInterface.ACTION_MESSAGE_RECEIVED.equals(action)) {
|
||||
handlingMessageReceive(intent);
|
||||
} else if (JPushInterface.ACTION_NOTIFICATION_RECEIVED.equals(action)) {
|
||||
handlingNotificationReceive(context, intent);
|
||||
} else if (JPushInterface.ACTION_NOTIFICATION_OPENED.equals(action)) {
|
||||
handlingNotificationOpen(context, intent);
|
||||
} else if (JPushInterface.ACTION_RICHPUSH_CALLBACK.equals(action)) {
|
||||
// 当在 HTML 页面中调用 JPushWeb.triggerNativeAction(String params) 方法时触发此方法,
|
||||
// 再进行相关的操作。
|
||||
|
||||
} else {
|
||||
Log.d(TAG, "Unhandled intent - " + intent.getAction());
|
||||
Log.d(TAG, "Unhandled intent - " + action);
|
||||
}
|
||||
|
||||
}
|
||||
private void handlingReceivedMessage(Intent intent) {
|
||||
String msg = intent.getStringExtra(JPushInterface.EXTRA_MESSAGE);
|
||||
Map<String,Object> extras = getNotificationExtras(intent);
|
||||
|
||||
|
||||
JPushPlugin.transmitPush(msg, extras);
|
||||
}
|
||||
private void handlingNotificationOpen(Context context,Intent intent){
|
||||
Log.i(TAG, "---------------- handlingNotificationOpen");
|
||||
}
|
||||
|
||||
String alert = intent.getStringExtra(JPushInterface.EXTRA_ALERT);
|
||||
Map<String,Object> extras = getNotificationExtras(intent);
|
||||
|
||||
Intent launch = context.getPackageManager().getLaunchIntentForPackage(context.getPackageName());
|
||||
launch.addCategory(Intent.CATEGORY_LAUNCHER);
|
||||
launch.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK|Intent.FLAG_ACTIVITY_SINGLE_TOP);
|
||||
JPushPlugin.openNotificationAlert = alert;
|
||||
JPushPlugin.openNotificationExtras = extras;
|
||||
|
||||
JPushPlugin.transmitOpen(alert, extras);
|
||||
private void handlingMessageReceive(Intent intent) {
|
||||
String msg = intent.getStringExtra(JPushInterface.EXTRA_MESSAGE);
|
||||
Map<String, Object> extras = getNotificationExtras(intent);
|
||||
JPushPlugin.transmitMessageReceive(msg, extras);
|
||||
}
|
||||
|
||||
context.startActivity(launch);
|
||||
}
|
||||
private void handlingNotificationReceive(Context context,Intent intent){
|
||||
private void handlingNotificationOpen(Context context, Intent intent) {
|
||||
Log.i(TAG, "---------------- handlingNotificationOpen");
|
||||
|
||||
Log.i(TAG, "---------------- handlingNotificationReceive");
|
||||
String title = intent.getStringExtra(JPushInterface.EXTRA_NOTIFICATION_TITLE);
|
||||
JPushPlugin.openNotificationTitle = title;
|
||||
|
||||
String alert = intent.getStringExtra(JPushInterface.EXTRA_ALERT);
|
||||
JPushPlugin.openNotificationAlert = alert;
|
||||
|
||||
Map<String, Object> extras = getNotificationExtras(intent);
|
||||
JPushPlugin.openNotificationExtras = extras;
|
||||
|
||||
JPushPlugin.transmitNotificationOpen(title, alert, extras);
|
||||
|
||||
Intent launch = context.getPackageManager().getLaunchIntentForPackage(
|
||||
context.getPackageName());
|
||||
launch.addCategory(Intent.CATEGORY_LAUNCHER);
|
||||
launch.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP);
|
||||
context.startActivity(launch);
|
||||
}
|
||||
|
||||
private void handlingNotificationReceive(Context context, Intent intent) {
|
||||
Log.i(TAG, "---------------- handlingNotificationReceive");
|
||||
|
||||
Intent launch = context.getPackageManager().getLaunchIntentForPackage(
|
||||
context.getPackageName());
|
||||
launch.addCategory(Intent.CATEGORY_LAUNCHER);
|
||||
launch.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP);
|
||||
|
||||
String title = intent.getStringExtra(JPushInterface.EXTRA_NOTIFICATION_TITLE);
|
||||
JPushPlugin.notificationTitle = title;
|
||||
|
||||
String alert = intent.getStringExtra(JPushInterface.EXTRA_ALERT);
|
||||
JPushPlugin.notificationAlert = alert;
|
||||
|
||||
Map<String, Object> extras = getNotificationExtras(intent);
|
||||
JPushPlugin.notificationExtras = extras;
|
||||
|
||||
JPushPlugin.transmitNotificationReceive(title, alert, extras);
|
||||
}
|
||||
|
||||
private Map<String, Object> getNotificationExtras(Intent intent) {
|
||||
Map<String, Object> extrasMap = new HashMap<String, Object>();
|
||||
for (String key : intent.getExtras().keySet()) {
|
||||
if (!IGNORED_EXTRAS_KEYS.contains(key)) {
|
||||
if (key.equals(JPushInterface.EXTRA_NOTIFICATION_ID)) {
|
||||
extrasMap.put(key, intent.getIntExtra(key, 0));
|
||||
} else {
|
||||
extrasMap.put(key, intent.getStringExtra(key));
|
||||
}
|
||||
}
|
||||
}
|
||||
return extrasMap;
|
||||
}
|
||||
|
||||
String alert = intent.getStringExtra(JPushInterface.EXTRA_ALERT);
|
||||
Map<String,Object> extras = getNotificationExtras(intent);
|
||||
|
||||
Intent launch = context.getPackageManager().getLaunchIntentForPackage(context.getPackageName());
|
||||
launch.addCategory(Intent.CATEGORY_LAUNCHER);
|
||||
launch.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK|Intent.FLAG_ACTIVITY_SINGLE_TOP);
|
||||
|
||||
JPushPlugin.notificationAlert = alert;
|
||||
JPushPlugin.notificationExtras = extras;
|
||||
|
||||
JPushPlugin.transmitReceive(alert, extras);
|
||||
}
|
||||
private Map<String, Object> getNotificationExtras(Intent intent) {
|
||||
Map<String, Object> extrasMap = new HashMap<String, Object>();
|
||||
|
||||
for (String key : intent.getExtras().keySet()) {
|
||||
if (!IGNORED_EXTRAS_KEYS.contains(key)) {
|
||||
Log.e("key","key:"+key);
|
||||
if (key.equals(JPushInterface.EXTRA_NOTIFICATION_ID)){
|
||||
extrasMap.put(key, intent.getIntExtra(key,0));
|
||||
}else{
|
||||
extrasMap.put(key, intent.getStringExtra(key));
|
||||
}
|
||||
}
|
||||
}
|
||||
return extrasMap;
|
||||
}
|
||||
private static final List<String> IGNORED_EXTRAS_KEYS =
|
||||
Arrays.asList("cn.jpush.android.TITLE","cn.jpush.android.MESSAGE","cn.jpush.android.APPKEY","cn.jpush.android.NOTIFICATION_CONTENT_TITLE");
|
||||
}
|
||||
|
||||
Binary file not shown.
BIN
src/android/arm64-v8a/libjpush219.so
Normal file
BIN
src/android/arm64-v8a/libjpush219.so
Normal file
Binary file not shown.
Binary file not shown.
BIN
src/android/armeabi-v7a/libjpush219.so
Normal file
BIN
src/android/armeabi-v7a/libjpush219.so
Normal file
Binary file not shown.
Binary file not shown.
BIN
src/android/armeabi/libjpush219.so
Normal file
BIN
src/android/armeabi/libjpush219.so
Normal file
Binary file not shown.
BIN
src/android/ic_richpush_actionbar_back.png
Normal file
BIN
src/android/ic_richpush_actionbar_back.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 695 B |
BIN
src/android/ic_richpush_actionbar_divider.png
Normal file
BIN
src/android/ic_richpush_actionbar_divider.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 181 B |
Binary file not shown.
BIN
src/android/jpush-android-2.1.9.jar
Normal file
BIN
src/android/jpush-android-2.1.9.jar
Normal file
Binary file not shown.
15
src/android/jpush_popwin_layout.xml
Normal file
15
src/android/jpush_popwin_layout.xml
Normal file
@@ -0,0 +1,15 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/popLayoutId"
|
||||
style="@style/MyDialogStyle"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="280dp"
|
||||
android:layout_height="250dp" >
|
||||
|
||||
<WebView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:id="@+id/wvPopwin"/>
|
||||
|
||||
</LinearLayout>
|
||||
13
src/android/jpush_style.xml
Normal file
13
src/android/jpush_style.xml
Normal file
@@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<style name="MyDialogStyle">
|
||||
<item name="android:windowBackground">@android:color/transparent</item>
|
||||
<item name="android:windowFrame">@null</item>
|
||||
<item name="android:windowNoTitle">true</item>
|
||||
<item name="android:windowIsFloating">true</item>
|
||||
<item name="android:windowIsTranslucent">true</item>
|
||||
<item name="android:windowContentOverlay">@null</item>
|
||||
<item name="android:windowAnimationStyle">@android:style/Animation.Dialog</item>
|
||||
<item name="android:backgroundDimEnabled">true</item>
|
||||
</style>
|
||||
</resources>
|
||||
51
src/android/jpush_webview_layout.xml
Normal file
51
src/android/jpush_webview_layout.xml
Normal file
@@ -0,0 +1,51 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<cn.jpush.android.ui.FullScreenView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/actionbarLayoutId"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical" >
|
||||
|
||||
<RelativeLayout
|
||||
android:id="@+id/rlRichpushTitleBar"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="40.0dp"
|
||||
android:background="#29313a">
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/imgRichpushBtnBack"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerVertical="true"
|
||||
android:layout_marginLeft="9dp"
|
||||
android:layout_marginRight="10dp"
|
||||
android:background="@drawable/richpush_btn_selector" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/imgView"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerVertical="true"
|
||||
android:layout_toRightOf="@id/imgRichpushBtnBack"
|
||||
android:clickable="false"
|
||||
android:src="@drawable/ic_richpush_actionbar_divider" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvRichpushTitle"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerVertical="true"
|
||||
android:layout_marginLeft="7dp"
|
||||
android:layout_toRightOf="@id/imgView"
|
||||
android:clickable="false"
|
||||
android:text=" "
|
||||
android:textSize="20sp"
|
||||
android:textColor="#ffffff" />
|
||||
</RelativeLayout>
|
||||
|
||||
<WebView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:id="@+id/fullWebView"
|
||||
android:background="#000000" />
|
||||
|
||||
</cn.jpush.android.ui.FullScreenView>
|
||||
21
src/android/richpush_btn_selector.xml
Normal file
21
src/android/richpush_btn_selector.xml
Normal file
@@ -0,0 +1,21 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
|
||||
<!-- 获得焦点但未按下时的背景图片 -->
|
||||
<item
|
||||
android:state_focused="true"
|
||||
android:state_enabled="true"
|
||||
android:state_pressed="false"
|
||||
android:drawable="@drawable/ic_richpush_actionbar_back" />
|
||||
<!-- 按下时的背景图片 -->
|
||||
<item
|
||||
android:state_enabled="true"
|
||||
android:state_pressed="true"
|
||||
android:drawable="@android:color/darker_gray" />
|
||||
<!-- 按下时的背景图片 -->
|
||||
<item
|
||||
android:state_enabled="true"
|
||||
android:state_checked="true"
|
||||
android:drawable="@android:color/darker_gray" />
|
||||
<!-- 默认时的背景图片 -->
|
||||
<item android:drawable="@drawable/ic_richpush_actionbar_back" />
|
||||
</selector>
|
||||
BIN
src/android/x86/libjpush219.so
Normal file
BIN
src/android/x86/libjpush219.so
Normal file
Binary file not shown.
BIN
src/android/x86_64/libjpush219.so
Normal file
BIN
src/android/x86_64/libjpush219.so
Normal file
Binary file not shown.
@@ -7,9 +7,9 @@
|
||||
//
|
||||
|
||||
#import "AppDelegate.h"
|
||||
#import <UserNotifications/UserNotifications.h>
|
||||
#import "JPUSHService.h"
|
||||
|
||||
@interface AppDelegate (JPush)
|
||||
|
||||
//@property(nonatomic,strong)NSDictionary *luanchOption;
|
||||
|
||||
@interface AppDelegate (JPush) <JPUSHRegisterDelegate>
|
||||
-(void)registerForIos10RemoteNotification;
|
||||
@end
|
||||
|
||||
@@ -7,87 +7,92 @@
|
||||
//
|
||||
|
||||
#import "AppDelegate+JPush.h"
|
||||
#import <objc/runtime.h>
|
||||
#import "JPushPlugin.h"
|
||||
#import "JPUSHService.h"
|
||||
#import <objc/runtime.h>
|
||||
#import <AdSupport/AdSupport.h>
|
||||
#import <UserNotifications/UserNotifications.h>
|
||||
|
||||
|
||||
//static char launchNotificationKey;
|
||||
|
||||
@implementation AppDelegate (JPush)
|
||||
|
||||
+(void)load{
|
||||
|
||||
|
||||
Method origin;
|
||||
Method swizzle;
|
||||
|
||||
|
||||
origin=class_getInstanceMethod([self class],@selector(init));
|
||||
swizzle=class_getInstanceMethod([self class], @selector(init_plus));
|
||||
method_exchangeImplementations(origin, swizzle);
|
||||
}
|
||||
|
||||
-(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];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
|
||||
[JPUSHService registerDeviceToken:deviceToken];
|
||||
}
|
||||
|
||||
-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo{
|
||||
|
||||
[JPUSHService handleRemoteNotification:userInfo];
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:kJPushPluginReceiveNotification
|
||||
object:userInfo];
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:kJPushPluginReceiveNotification object:userInfo];
|
||||
}
|
||||
|
||||
-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler{
|
||||
|
||||
[JPUSHService handleRemoteNotification:userInfo];
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:kJPushPluginReceiveNotification
|
||||
object:userInfo];
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:kJPushPluginReceiveNotification object:userInfo];
|
||||
completionHandler(UIBackgroundFetchResultNewData);
|
||||
|
||||
}
|
||||
|
||||
- (void)application:(UIApplication *)application
|
||||
didReceiveLocalNotification:(UILocalNotification *)notification {
|
||||
[JPUSHService showLocalNotificationAtFront:notification identifierKey:nil];
|
||||
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification {
|
||||
[JPUSHService showLocalNotificationAtFront:notification identifierKey:nil];
|
||||
}
|
||||
|
||||
|
||||
- (void)applicationWillEnterForeground:(UIApplication *)application {
|
||||
// [application setApplicationIconBadgeNumber:0];
|
||||
// [application cancelAllLocalNotifications];
|
||||
// [application setApplicationIconBadgeNumber:0];
|
||||
// [application cancelAllLocalNotifications];
|
||||
}
|
||||
|
||||
|
||||
- (void)applicationDidEnterBackground:(UIApplication *)application {
|
||||
// [[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];
|
||||
// [[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];
|
||||
}
|
||||
|
||||
-(void)jpushNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(NSInteger))completionHandler{
|
||||
|
||||
NSMutableDictionary *userInfo = [NSMutableDictionary dictionaryWithDictionary:notification.request.content.userInfo];
|
||||
|
||||
//delegate里不能声明变量,所以采用关联对象这种技术绕过这个限制
|
||||
//-(NSDictionary *)luanchOption{
|
||||
// return objc_getAssociatedObject(self, &launchNotificationKey);
|
||||
//}
|
||||
//-(void)setLuanchOption:(NSDictionary *)luanchOption{
|
||||
// objc_setAssociatedObject(self, &launchNotificationKey, luanchOption, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
|
||||
//}
|
||||
//-(void)dealloc{
|
||||
// self.luanchOption=nil;
|
||||
//}
|
||||
[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
|
||||
|
||||
@@ -9,30 +9,68 @@
|
||||
#import <Cordova/CDV.h>
|
||||
|
||||
#define kJPushPluginReceiveNotification @"JPushPluginReceiveNofication"
|
||||
#define kJPushPluginiOS10ForegroundReceiveNotification @"kJPushPluginiOS10ForegroundReceiveNotification"
|
||||
#define kJPushPluginiOS10ClickNotification @"kJPushPluginiOS10ClickNotification"
|
||||
|
||||
|
||||
@interface JPushPlugin : CDVPlugin{
|
||||
|
||||
|
||||
}
|
||||
|
||||
+(void)setLaunchOptions:(NSDictionary *)theLaunchOptions;
|
||||
|
||||
//以下为js中可调用接口
|
||||
//设置标签、别名
|
||||
-(void)setTagsWithAlias:(CDVInvokedUrlCommand*)command;
|
||||
-(void)setTags:(CDVInvokedUrlCommand*)command;
|
||||
-(void)setAlias:(CDVInvokedUrlCommand*)command;
|
||||
|
||||
//获取 RegistrationID
|
||||
-(void)getRegistrationID:(CDVInvokedUrlCommand*)command;
|
||||
|
||||
//页面统计
|
||||
-(void)startLogPageView:(CDVInvokedUrlCommand*)command;
|
||||
-(void)stopLogPageView:(CDVInvokedUrlCommand*)command;
|
||||
-(void)beginLogPageView:(CDVInvokedUrlCommand*)command;
|
||||
|
||||
// 设置角标到服务器, 服务器下一次发消息时,会设置成这个值
|
||||
//设置角标到服务器,服务器下一次发消息时,会设置成这个值
|
||||
//本接口不会改变应用本地的角标值.
|
||||
-(void)setBadge:(CDVInvokedUrlCommand*)command;
|
||||
//相当于 [setBadge:0]
|
||||
-(void)resetBadge:(CDVInvokedUrlCommand*)command;
|
||||
|
||||
|
||||
//改变应用本地的角标值.
|
||||
//应用本地的角标值设置/获取
|
||||
-(void)setApplicationIconBadgeNumber:(CDVInvokedUrlCommand*)command;
|
||||
//获取应用本地的角标值.
|
||||
-(void)getApplicationIconBadgeNumber:(CDVInvokedUrlCommand*)command;
|
||||
|
||||
//停止与恢复推送
|
||||
-(void)stopPush:(CDVInvokedUrlCommand*)command;
|
||||
-(void)resumePush:(CDVInvokedUrlCommand*)command;
|
||||
-(void)isPushStopped:(CDVInvokedUrlCommand*)command;
|
||||
|
||||
//开关日志
|
||||
-(void)setDebugModeFromIos:(CDVInvokedUrlCommand*)command;
|
||||
-(void)setLogOFF:(CDVInvokedUrlCommand*)command;
|
||||
-(void)crashLogON:(CDVInvokedUrlCommand*)command;
|
||||
|
||||
//本地推送
|
||||
-(void)setLocalNotification:(CDVInvokedUrlCommand*)command;
|
||||
-(void)deleteLocalNotificationWithIdentifierKey:(CDVInvokedUrlCommand*)command;
|
||||
-(void)clearAllLocalNotifications:(CDVInvokedUrlCommand*)command;
|
||||
|
||||
//地理位置上报 [latitude,longitude]
|
||||
-(void)setLocation:(CDVInvokedUrlCommand*)command;
|
||||
|
||||
//检查用户的推送设置情况
|
||||
-(void)getUserNotificationSettings:(CDVInvokedUrlCommand*)command;
|
||||
|
||||
/*
|
||||
* 以下为js中可监听到的事件
|
||||
* jpush.openNotification 点击推送消息启动或唤醒app
|
||||
* jpush.setTagsWithAlias 设置标签、别名完成
|
||||
* jpush.receiveMessage 收到自定义消息
|
||||
* jpush.receiveNotification 前台收到推送
|
||||
* jpush.backgroundNotification 后台收到推送
|
||||
*/
|
||||
|
||||
@end
|
||||
|
||||
@@ -9,453 +9,438 @@
|
||||
#import "JPushPlugin.h"
|
||||
#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";
|
||||
static NSString *const JP_APP_ISPRODUCTION = @"IsProduction";
|
||||
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;
|
||||
|
||||
static NSString *const JM_APP_KEY = @"APP_KEY";
|
||||
static NSString *const JM_APP_CHANNEL = @"CHANNEL";
|
||||
static NSString *const JM_APP_ISPRODUCTION = @"IsProduction";
|
||||
@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
|
||||
|
||||
static NSString *const JMessageConfigFileName = @"PushConfig";
|
||||
@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()
|
||||
|
||||
static NSDictionary *_luanchOptions=nil;
|
||||
@end
|
||||
|
||||
@implementation JPushPlugin
|
||||
|
||||
|
||||
+(void)setLaunchOptions:(NSDictionary *)theLaunchOptions{
|
||||
_luanchOptions=theLaunchOptions;
|
||||
[JPUSHService setDebugMode];
|
||||
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];
|
||||
}
|
||||
|
||||
//read appkey and channel from JMessageConfig.plist
|
||||
NSString *plistPath = [[NSBundle mainBundle] pathForResource:JMessageConfigFileName ofType:@"plist"];
|
||||
if (plistPath == nil) {
|
||||
NSLog(@"error: PushConfig.plist not found");
|
||||
assert(0);
|
||||
}
|
||||
|
||||
NSMutableDictionary *plistData = [[NSMutableDictionary alloc] initWithContentsOfFile:plistPath];
|
||||
NSString * appkey = [plistData valueForKey:JM_APP_KEY];
|
||||
NSString * channel = [plistData valueForKey:JM_APP_CHANNEL];
|
||||
NSNumber * isProduction = [plistData valueForKey:JM_APP_ISPRODUCTION];
|
||||
|
||||
if (!appkey || appkey.length == 0) {
|
||||
NSLog(@"error: app key not found in JMessageConfig.plist ");
|
||||
assert(0);
|
||||
}
|
||||
|
||||
[JPUSHService setupWithOption:_luanchOptions appKey:appkey
|
||||
channel:channel apsForProduction:[isProduction boolValue] ];
|
||||
|
||||
}
|
||||
|
||||
|
||||
#pragma mark- 外部接口
|
||||
-(void)stopPush:(CDVInvokedUrlCommand*)command{
|
||||
|
||||
[[UIApplication sharedApplication]unregisterForRemoteNotifications];
|
||||
[[UIApplication sharedApplication]unregisterForRemoteNotifications];
|
||||
}
|
||||
|
||||
|
||||
-(void)resumePush:(CDVInvokedUrlCommand*)command{
|
||||
|
||||
#if __IPHONE_OS_VERSION_MAX_ALLOWED > __IPHONE_7_1
|
||||
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];
|
||||
}
|
||||
#else
|
||||
//categories 必须为nil
|
||||
[JPUSHService registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge |
|
||||
UIRemoteNotificationTypeSound |
|
||||
UIRemoteNotificationTypeAlert)
|
||||
categories:nil];
|
||||
#endif
|
||||
|
||||
[JPushPlugin registerForRemoteNotification];
|
||||
}
|
||||
|
||||
|
||||
-(void)isPushStopped:(CDVInvokedUrlCommand*)command{
|
||||
|
||||
NSNumber *result;
|
||||
if ([[UIApplication sharedApplication] isRegisteredForRemoteNotifications ]) {
|
||||
result=@(0);
|
||||
}else{
|
||||
result=@(1);
|
||||
}
|
||||
CDVPluginResult * pushResult=[self pluginResultForValue:result];
|
||||
if (pushResult) {
|
||||
[self succeedWithPluginResult:pushResult withCallbackID:command.callbackId];
|
||||
} else {
|
||||
[self failWithCallbackID:command.callbackId];
|
||||
}
|
||||
NSNumber *result;
|
||||
if ([[UIApplication sharedApplication] isRegisteredForRemoteNotifications]) {
|
||||
result = @(0);
|
||||
}else{
|
||||
result = @(1);
|
||||
}
|
||||
[self handleResultWithValue:result command:command];
|
||||
}
|
||||
|
||||
|
||||
-(void)initial:(CDVInvokedUrlCommand*)command{
|
||||
//do nithng,because Cordova plugin use lazy load mode.
|
||||
//do nithng,because Cordova plugin use lazy load mode.
|
||||
}
|
||||
|
||||
|
||||
|
||||
#ifdef __CORDOVA_4_0_0
|
||||
|
||||
- (void)pluginInitialize {
|
||||
NSLog(@"### pluginInitialize ");
|
||||
[self initNotifications];
|
||||
NSLog(@"### pluginInitialize ");
|
||||
[self initNotifications];
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
- (CDVPlugin*)initWithWebView:(UIWebView*)theWebView{
|
||||
NSLog(@"### initWithWebView ");
|
||||
if (self=[super initWithWebView:theWebView]) {
|
||||
[self initNotifications];
|
||||
|
||||
}
|
||||
return self;
|
||||
NSLog(@"### initWithWebView ");
|
||||
if (self=[super initWithWebView:theWebView]) {
|
||||
[self initNotifications];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
-(void)initNotifications {
|
||||
|
||||
NSNotificationCenter *defaultCenter = [NSNotificationCenter defaultCenter];
|
||||
[defaultCenter addObserver:self
|
||||
selector:@selector(networkDidReceiveMessage:)
|
||||
name:kJPFNetworkDidReceiveMessageNotification
|
||||
object:nil];
|
||||
|
||||
[defaultCenter addObserver:self
|
||||
selector:@selector(networkDidReceiveNotification:)
|
||||
name:kJPushPluginReceiveNotification
|
||||
object:nil];
|
||||
|
||||
if (_luanchOptions) {
|
||||
NSDictionary *userInfo = [_luanchOptions
|
||||
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]];
|
||||
});
|
||||
|
||||
}
|
||||
NSNotificationCenter *defaultCenter = [NSNotificationCenter defaultCenter];
|
||||
[defaultCenter addObserver:self
|
||||
selector:@selector(networkDidReceiveMessage:)
|
||||
name:kJPFNetworkDidReceiveMessageNotification
|
||||
object:nil];
|
||||
|
||||
[defaultCenter addObserver:self
|
||||
selector:@selector(networkDidReceiveNotification:)
|
||||
name:kJPushPluginReceiveNotification
|
||||
object:nil];
|
||||
|
||||
[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]]];
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
-(void)setTagsWithAlias:(CDVInvokedUrlCommand*)command{
|
||||
NSArray *arguments=command.arguments;
|
||||
if (!arguments||[arguments count]<2) {
|
||||
|
||||
NSLog(@"#### setTagsWithAlias param is less");
|
||||
return ;
|
||||
}
|
||||
NSString *alias=[arguments objectAtIndex:0];
|
||||
NSArray *arrayTags=[arguments objectAtIndex:1];
|
||||
|
||||
NSLog(@"#### setTagsWithAlias alias is %@, tags is %@",alias,arrayTags);
|
||||
|
||||
NSSet* set=[NSSet setWithArray:arrayTags];
|
||||
[JPUSHService setTags:set
|
||||
alias:alias
|
||||
callbackSelector:@selector(tagsWithAliasCallback:tags:alias:)
|
||||
object:self];
|
||||
NSArray *arguments = command.arguments;
|
||||
NSString *alias;
|
||||
NSArray *tags;
|
||||
if (!arguments || [arguments count] < 2) {
|
||||
NSLog(@"#### setTagsWithAlias param is less");
|
||||
return ;
|
||||
}else{
|
||||
alias = arguments[0];
|
||||
tags = arguments[1];
|
||||
}
|
||||
|
||||
NSLog(@"#### setTagsWithAlias alias is %@, tags is %@",alias,tags);
|
||||
|
||||
[JPUSHService setTags:[NSSet setWithArray:tags]
|
||||
alias:alias
|
||||
callbackSelector:@selector(tagsWithAliasCallback:tags:alias:)
|
||||
object:self];
|
||||
}
|
||||
|
||||
|
||||
|
||||
-(void)setTags:(CDVInvokedUrlCommand *)command{
|
||||
|
||||
|
||||
NSArray *arguments=[command arguments];
|
||||
NSString *tags=[arguments objectAtIndex:0];
|
||||
|
||||
NSLog(@"#### setTags %@",tags);
|
||||
|
||||
NSArray *array=[tags componentsSeparatedByString:@","];
|
||||
[JPUSHService setTags:[NSSet setWithArray:array]
|
||||
callbackSelector:@selector(tagsWithAliasCallback:tags:alias:)
|
||||
object:self];
|
||||
|
||||
NSArray *tags = command.arguments;
|
||||
|
||||
NSLog(@"#### setTags %@",tags);
|
||||
|
||||
[JPUSHService setTags:[NSSet setWithArray:tags]
|
||||
callbackSelector:@selector(tagsWithAliasCallback:tags:alias:)
|
||||
object:self];
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
-(void)setAlias:(CDVInvokedUrlCommand *)command{
|
||||
|
||||
NSArray *arguments=[command arguments];
|
||||
NSLog(@"#### setAlias %@",arguments);
|
||||
[JPUSHService setAlias:[arguments objectAtIndex:0]
|
||||
callbackSelector:@selector(tagsWithAliasCallback:tags:alias:)
|
||||
object:self];
|
||||
|
||||
|
||||
NSLog(@"#### setAlias %@",command.arguments);
|
||||
[JPUSHService setAlias:command.arguments[0]
|
||||
callbackSelector:@selector(tagsWithAliasCallback:tags:alias:)
|
||||
object:self];
|
||||
}
|
||||
|
||||
|
||||
|
||||
-(void)getRegistrationID:(CDVInvokedUrlCommand*)command{
|
||||
NSString* registrationID = [JPUSHService registrationID];
|
||||
NSLog(@"### getRegistrationID %@",registrationID);
|
||||
|
||||
CDVPluginResult *result=[self pluginResultForValue:registrationID];
|
||||
if (result) {
|
||||
[self succeedWithPluginResult:result withCallbackID:command.callbackId];
|
||||
} else {
|
||||
[self failWithCallbackID:command.callbackId];
|
||||
}
|
||||
NSString* registrationID = [JPUSHService registrationID];
|
||||
NSLog(@"### getRegistrationID %@",registrationID);
|
||||
[self handleResultWithValue:registrationID command:command];
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
-(void)tagsWithAliasCallback:(int)resultCode tags:(NSSet *)tags alias:(NSString *)alias{
|
||||
|
||||
NSDictionary *dict=[NSDictionary dictionaryWithObjectsAndKeys:
|
||||
[NSNumber numberWithInt:resultCode],@"resultCode",
|
||||
tags==nil?[NSNull null]:[tags allObjects],@"tags",
|
||||
alias==nil?[NSNull null]:alias,@"alias",nil];
|
||||
NSMutableDictionary *data = [NSMutableDictionary dictionary];
|
||||
[data setObject:[NSNumber numberWithInt:resultCode] forKey:@"resultCode"];
|
||||
[data setObject:tags==nil?[NSNull null]:[tags allObjects] forKey:@"tags"];
|
||||
[data setObject:alias==nil?[NSNull null]:alias forKey:@"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 writeJavascript:[NSString stringWithFormat:@"window.plugins.jPushPlugin.pushCallback('%@')",jsonString]];
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
||||
-(void)startLogPageView:(CDVInvokedUrlCommand*)command{
|
||||
NSArray *arguments=command.arguments;
|
||||
if (!arguments||[arguments count]<1) {
|
||||
NSLog(@"startLogPageView argument error");
|
||||
return ;
|
||||
}
|
||||
NSString * pageName=[arguments objectAtIndex:0];
|
||||
if (pageName) {
|
||||
[JPUSHService startLogPageView:pageName];
|
||||
}
|
||||
NSArray *arguments = command.arguments;
|
||||
if (!arguments || [arguments count] < 1) {
|
||||
NSLog(@"startLogPageView argument error");
|
||||
return ;
|
||||
}
|
||||
NSString * pageName = arguments[0];
|
||||
if (pageName) {
|
||||
[JPUSHService startLogPageView:pageName];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
-(void)stopLogPageView:(CDVInvokedUrlCommand*)command{
|
||||
NSArray *arguments=command.arguments;
|
||||
if (!arguments||[arguments count]<1) {
|
||||
NSLog(@"stopLogPageView argument error");
|
||||
return ;
|
||||
}
|
||||
NSString * pageName=[arguments objectAtIndex:0];
|
||||
if (pageName) {
|
||||
[JPUSHService stopLogPageView:pageName];
|
||||
}
|
||||
|
||||
NSArray *arguments = command.arguments;
|
||||
if (!arguments || [arguments count] < 1) {
|
||||
NSLog(@"stopLogPageView argument error");
|
||||
return ;
|
||||
}
|
||||
NSString * pageName = arguments[0];
|
||||
if (pageName) {
|
||||
[JPUSHService stopLogPageView:pageName];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
-(void)beginLogPageView:(CDVInvokedUrlCommand*)command{
|
||||
NSArray *arguments=command.arguments;
|
||||
if (!arguments||[arguments count]<2) {
|
||||
NSLog(@"beginLogPageView argument error");
|
||||
return ;
|
||||
}
|
||||
NSString * pageName=[arguments objectAtIndex:0];
|
||||
int duration=[[arguments objectAtIndex:0]intValue];
|
||||
if (pageName) {
|
||||
[JPUSHService beginLogPageView:pageName duration:duration];
|
||||
}
|
||||
|
||||
NSArray *arguments = command.arguments;
|
||||
if (!arguments || [arguments count] < 2) {
|
||||
NSLog(@"beginLogPageView argument error");
|
||||
return ;
|
||||
}
|
||||
NSString * pageName = arguments[0];
|
||||
int duration = [arguments[0] intValue];
|
||||
if (pageName) {
|
||||
[JPUSHService beginLogPageView:pageName duration:duration];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
-(void)setBadge:(CDVInvokedUrlCommand*)command{
|
||||
NSArray *argument=command.arguments;
|
||||
if ([argument count]<1) {
|
||||
NSLog(@"setBadge argument error!");
|
||||
return;
|
||||
}
|
||||
NSNumber *badge=[argument objectAtIndex:0];
|
||||
[JPUSHService setBadge:[badge intValue]];
|
||||
NSArray *argument = command.arguments;
|
||||
if ([argument count] < 1) {
|
||||
NSLog(@"setBadge argument error!");
|
||||
return;
|
||||
}
|
||||
NSNumber *badge = argument[0];
|
||||
[JPUSHService setBadge:[badge intValue]];
|
||||
}
|
||||
|
||||
|
||||
|
||||
-(void)resetBadge:(CDVInvokedUrlCommand*)command{
|
||||
[JPUSHService resetBadge];
|
||||
[JPUSHService resetBadge];
|
||||
}
|
||||
|
||||
|
||||
-(void)setApplicationIconBadgeNumber:(CDVInvokedUrlCommand *)command{
|
||||
//
|
||||
NSArray *argument=command.arguments;
|
||||
if ([argument count]<1) {
|
||||
NSLog(@"setBadge argument error!");
|
||||
return;
|
||||
}
|
||||
NSNumber *badge=[argument objectAtIndex:0];
|
||||
[UIApplication sharedApplication].applicationIconBadgeNumber=[badge intValue];
|
||||
//
|
||||
NSArray *argument = command.arguments;
|
||||
if ([argument count] < 1) {
|
||||
NSLog(@"setBadge argument error!");
|
||||
return;
|
||||
}
|
||||
NSNumber *badge = [argument objectAtIndex:0];
|
||||
[UIApplication sharedApplication].applicationIconBadgeNumber = [badge intValue];
|
||||
}
|
||||
|
||||
|
||||
-(void)getApplicationIconBadgeNumber:(CDVInvokedUrlCommand *)command {
|
||||
NSInteger num = [UIApplication sharedApplication].applicationIconBadgeNumber;
|
||||
CDVPluginResult *result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsInt:num];
|
||||
[self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
|
||||
NSInteger num = [UIApplication sharedApplication].applicationIconBadgeNumber;
|
||||
NSNumber *number = [NSNumber numberWithInteger:num];
|
||||
[self handleResultWithValue:number command:command];
|
||||
}
|
||||
|
||||
|
||||
|
||||
-(void)setDebugModeFromIos:(CDVInvokedUrlCommand*)command{
|
||||
|
||||
[JPUSHService setDebugMode];
|
||||
[JPUSHService setDebugMode];
|
||||
}
|
||||
|
||||
|
||||
|
||||
-(void)setLogOFF:(CDVInvokedUrlCommand*)command{
|
||||
|
||||
[JPUSHService setLogOFF];
|
||||
[JPUSHService setLogOFF];
|
||||
}
|
||||
|
||||
|
||||
|
||||
- (void)failWithCallbackID:(NSString *)callbackID {
|
||||
CDVPluginResult *result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR];
|
||||
[self.commandDelegate sendPluginResult:result callbackId:callbackID];
|
||||
-(void)crashLogON:(CDVInvokedUrlCommand*)command{
|
||||
[JPUSHService crashLogON];
|
||||
}
|
||||
|
||||
|
||||
|
||||
- (void)succeedWithPluginResult:(CDVPluginResult *)result withCallbackID:(NSString *)callbackID {
|
||||
[self.commandDelegate sendPluginResult:result callbackId:callbackID];
|
||||
-(void)setLocalNotification:(CDVInvokedUrlCommand*)command{
|
||||
NSArray *arguments = command.arguments;
|
||||
NSDate *date = arguments[0] == [NSNull null] ? nil : [NSDate dateWithTimeIntervalSinceNow:[((NSString*)arguments[0]) intValue]];
|
||||
NSString *alertBody = arguments[1] == [NSNull null] ? nil : (NSString*)arguments[1];
|
||||
int badge = arguments[2] == [NSNull null] ? 0 : [(NSString*)arguments[2] intValue];
|
||||
NSString *idKey = arguments[3] == [NSNull null] ? nil : (NSString*)arguments[3];
|
||||
NSDictionary *dict = arguments[4] == [NSNull null] ? nil : (NSDictionary*)arguments[4];
|
||||
[JPUSHService setLocalNotification:date alertBody:alertBody badge:badge alertAction:nil identifierKey:idKey userInfo:dict soundName:nil];
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
- (CDVPluginResult *)pluginResultForValue:(id)value {
|
||||
|
||||
CDVPluginResult *result;
|
||||
if ([value isKindOfClass:[NSString class]]) {
|
||||
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK
|
||||
messageAsString:[value stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
|
||||
} else if ([value isKindOfClass:[NSNumber class]]) {
|
||||
CFNumberType numberType = CFNumberGetType((CFNumberRef)value);
|
||||
//note: underlyingly, BOOL values are typedefed as char
|
||||
if (numberType == kCFNumberIntType || numberType == kCFNumberCharType) {
|
||||
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsInt:[value intValue]];
|
||||
} else {
|
||||
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDouble:[value doubleValue]];
|
||||
-(void)deleteLocalNotificationWithIdentifierKey:(CDVInvokedUrlCommand*)command{
|
||||
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];
|
||||
}
|
||||
} else if ([value isKindOfClass:[NSArray class]]) {
|
||||
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsArray:value];
|
||||
} else if ([value isKindOfClass:[NSDictionary class]]) {
|
||||
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:value];
|
||||
} else if ([value isKindOfClass:[NSNull class]]) {
|
||||
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
|
||||
} else {
|
||||
NSLog(@"Cordova callback block returned unrecognized type: %@", NSStringFromClass([value class]));
|
||||
return nil;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
-(void)clearAllLocalNotifications:(CDVInvokedUrlCommand*)command{
|
||||
[JPUSHService clearAllLocalNotifications];
|
||||
}
|
||||
|
||||
-(void)setLocation:(CDVInvokedUrlCommand*)command{
|
||||
[JPUSHService setLatitude:[((NSString*)command.arguments[0]) doubleValue] longitude:[((NSString*)command.arguments[1]) doubleValue]];
|
||||
}
|
||||
|
||||
-(void)getUserNotificationSettings:(CDVInvokedUrlCommand*)command{
|
||||
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];
|
||||
[self handleResultWithValue:number command:command];
|
||||
}else{
|
||||
UIRemoteNotificationType type = [[UIApplication sharedApplication] enabledRemoteNotificationTypes];
|
||||
NSNumber *number = [NSNumber numberWithInteger:type];
|
||||
[self handleResultWithValue:number command:command];
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark - 内部方法
|
||||
+(void)setLaunchOptions:(NSDictionary *)theLaunchOptions{
|
||||
_launchOptions = theLaunchOptions;
|
||||
|
||||
[JPUSHService setDebugMode];
|
||||
|
||||
[JPushPlugin registerForRemoteNotification];
|
||||
|
||||
//read appkey and channel from PushConfig.plist
|
||||
NSString *plistPath = [[NSBundle mainBundle] pathForResource:JPushConfigFileName ofType:@"plist"];
|
||||
if (plistPath == nil) {
|
||||
NSLog(@"error: PushConfig.plist not found");
|
||||
assert(0);
|
||||
}
|
||||
|
||||
NSMutableDictionary *plistData = [[NSMutableDictionary alloc] initWithContentsOfFile:plistPath];
|
||||
NSString * appkey = [plistData valueForKey:JP_APP_KEY];
|
||||
NSString * channel = [plistData valueForKey:JP_APP_CHANNEL];
|
||||
NSNumber * isProduction = [plistData valueForKey:JP_APP_ISPRODUCTION];
|
||||
NSNumber *isIDFA = [plistData valueForKey:JP_APP_ISIDFA];
|
||||
|
||||
NSString *advertisingId = nil;
|
||||
if(isIDFA){
|
||||
advertisingId = [[[ASIdentifierManager sharedManager] advertisingIdentifier] UUIDString];
|
||||
}
|
||||
[JPUSHService setupWithOption:_launchOptions
|
||||
appKey:appkey
|
||||
channel:channel
|
||||
apsForProduction:[isProduction boolValue]
|
||||
advertisingIdentifier:advertisingId];
|
||||
|
||||
}
|
||||
|
||||
+(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;
|
||||
CDVCommandStatus status = CDVCommandStatus_OK;
|
||||
|
||||
if ([value isKindOfClass:[NSString class]]) {
|
||||
value = [value stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
|
||||
} else if ([value isKindOfClass:[NSNull class]]) {
|
||||
value = nil;
|
||||
}
|
||||
|
||||
if ([value isKindOfClass:[NSObject class]]) {
|
||||
result = [CDVPluginResult resultWithStatus:status messageAsString:value];//NSObject 类型都可以
|
||||
} else {
|
||||
NSLog(@"Cordova callback block returned unrecognized type: %@", NSStringFromClass([value class]));
|
||||
result = nil;
|
||||
}
|
||||
|
||||
if (!result) {
|
||||
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR];
|
||||
}
|
||||
[self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
|
||||
}
|
||||
|
||||
#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
|
||||
};
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[self.commandDelegate evalJs:[NSString stringWithFormat:@"cordova.fireDocumentEvent('jpush.setTagsWithAlias',%@)",[dict toJsonString]]];
|
||||
});
|
||||
}
|
||||
|
||||
- (void)networkDidReceiveMessage:(NSNotification *)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:@"window.plugins.jPushPlugin.receiveMessageIniOSCallback('%@')",jsonString]];
|
||||
|
||||
|
||||
});
|
||||
|
||||
if (notification) {
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
|
||||
[self.commandDelegate evalJs:[NSString stringWithFormat:@"cordova.fireDocumentEvent('jpush.receiveMessage',%@)",[notification.userInfo toJsonString]]];
|
||||
|
||||
[self.commandDelegate evalJs:[NSString stringWithFormat:@"window.plugins.jPushPlugin.receiveMessageIniOSCallback('%@')",[notification.userInfo toJsonString]]];
|
||||
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
-(void)networkDidReceiveNotification:(NSNotification *)notification{
|
||||
|
||||
NSError *error;
|
||||
NSDictionary *userInfo = [notification object];
|
||||
|
||||
-(void)networkDidReceiveNotification:(id)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:
|
||||
{
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[self.commandDelegate evalJs:[NSString stringWithFormat:@"cordova.fireDocumentEvent('jpush.receiveNotification',%@)",jsonString]];
|
||||
});
|
||||
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:userInfo options:0 error:&error];
|
||||
NSString *jsonString = [[NSString alloc]initWithData:jsonData encoding:NSUTF8StringEncoding];
|
||||
|
||||
switch ([UIApplication sharedApplication].applicationState) {
|
||||
case UIApplicationStateActive:{
|
||||
//前台收到
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[self.commandDelegate evalJs:[NSString stringWithFormat:@"cordova.fireDocumentEvent('jpush.receiveNotification',%@)",jsonString]];
|
||||
});
|
||||
break;
|
||||
}
|
||||
case UIApplicationStateInactive:{
|
||||
//后台点击
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[self.commandDelegate evalJs:[NSString stringWithFormat:@"cordova.fireDocumentEvent('jpush.openNotification',%@)",jsonString]];
|
||||
});
|
||||
break;
|
||||
}
|
||||
case UIApplicationStateBackground:{
|
||||
//后台收到
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[self.commandDelegate evalJs:[NSString stringWithFormat:@"cordova.fireDocumentEvent('jpush.backgoundNotification',%@)",jsonString]];
|
||||
});
|
||||
break;
|
||||
}
|
||||
default:
|
||||
//do nothing
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case UIApplicationStateInactive:
|
||||
case UIApplicationStateBackground:
|
||||
{
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[self.commandDelegate evalJs:[NSString stringWithFormat:@"cordova.fireDocumentEvent('jpush.openNotification',%@)",jsonString]];
|
||||
});
|
||||
|
||||
}
|
||||
break;
|
||||
default:
|
||||
//do nothing
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@end
|
||||
|
||||
@@ -8,5 +8,7 @@
|
||||
<string>Subscription</string>
|
||||
<key>IsProduction</key>
|
||||
<false/>
|
||||
<key>IsIDFA</key>
|
||||
<false/>
|
||||
</dict>
|
||||
</plist>
|
||||
|
||||
191
src/ios/lib/JPUSHService.h
Executable file → Normal file
191
src/ios/lib/JPUSHService.h
Executable file → Normal file
@@ -9,23 +9,102 @@
|
||||
* Copyright (c) 2011 ~ 2015 Shenzhen HXHG. All rights reserved.
|
||||
*/
|
||||
|
||||
#define JPUSH_VERSION_NUMBER 2.1.0
|
||||
#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); // 在通知中心显示的或待推送的标志,默认为NO,YES表示在通知中心显示的,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 核心头文件
|
||||
@@ -51,6 +130,7 @@ extern NSString *const kJPFServiceErrorNotification; // 错误提示
|
||||
* @param appKey 一个JPush 应用必须的,唯一的标识. 请参考 JPush 相关说明文档来获取这个标识.
|
||||
* @param channel 发布渠道. 可选.
|
||||
* @param isProduction 是否生产环境. 如果为开发状态,设置为 NO; 如果为生产状态,应改为 YES.
|
||||
* @param advertisingIdentifier 广告标识符(IDFA) 如果不需要使用IDFA,传nil.
|
||||
*
|
||||
* @discussion 提供SDK启动必须的参数, 来启动 SDK.
|
||||
* 此接口必须在 App 启动时调用, 否则 JPush SDK 将无法正常工作.
|
||||
@@ -61,6 +141,13 @@ extern NSString *const kJPFServiceErrorNotification; // 错误提示
|
||||
apsForProduction:(BOOL)isProduction;
|
||||
|
||||
|
||||
+ (void)setupWithOption:(NSDictionary *)launchingOption
|
||||
appKey:(NSString *)appKey
|
||||
channel:(NSString *)channel
|
||||
apsForProduction:(BOOL)isProduction
|
||||
advertisingIdentifier:(NSString *)advertisingId;
|
||||
|
||||
|
||||
///----------------------------------------------------
|
||||
/// @name APNs about 通知相关
|
||||
///----------------------------------------------------
|
||||
@@ -69,15 +156,24 @@ 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;
|
||||
|
||||
|
||||
/*!
|
||||
* @abstract 处理收到的 APNs 消息
|
||||
*/
|
||||
@@ -90,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;
|
||||
target:(id)theTarget __attribute__((deprecated("JPush 2.1.1 版本已过期")));
|
||||
|
||||
+ (void) setTags:(NSSet *)tags
|
||||
alias:(NSString *)alias
|
||||
@@ -108,9 +204,9 @@ callbackSelector:(SEL)cbSelector
|
||||
callbackSelector:(SEL)cbSelector
|
||||
object:(id)theTarget;
|
||||
|
||||
+ (void) setTags:(NSSet *)tags
|
||||
alias:(NSString *)alias
|
||||
fetchCompletionHandle:(void (^)(int iResCode, NSSet *iTags, NSString *iAlias))completionHandler;
|
||||
+ (void)setTags:(NSSet *)tags
|
||||
alias:(NSString *)alias
|
||||
fetchCompletionHandle:(void (^)(int iResCode, NSSet *iTags, NSString *iAlias))completionHandler;
|
||||
|
||||
+ (void) setTags:(NSSet *)tags
|
||||
aliasInbackground:(NSString *)alias;
|
||||
@@ -183,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个
|
||||
@@ -195,7 +320,7 @@ callbackSelector:(SEL)cbSelector
|
||||
* @param userInfo 自定义参数,可以用来标识推送和增加附加信息
|
||||
* @param soundName 自定义通知声音,设置为nil为默认声音
|
||||
*
|
||||
* @discussion 最多支持 64 个定义
|
||||
* @discussion 最多支持 64 个定义,此方法被[addNotification:]方法取代
|
||||
*/
|
||||
+ (UILocalNotification *)setLocalNotification:(NSDate *)fireDate
|
||||
alertBody:(NSString *)alertBody
|
||||
@@ -203,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 新参数)
|
||||
@@ -212,6 +337,7 @@ callbackSelector:(SEL)cbSelector
|
||||
* @param region 自定义参数
|
||||
* @param regionTriggersOnce 自定义参数
|
||||
* @param category 自定义参数
|
||||
* @discussion 此方法被[addNotification:]方法取代
|
||||
*/
|
||||
+ (UILocalNotification *)setLocalNotification:(NSDate *)fireDate
|
||||
alertBody:(NSString *)alertBody
|
||||
@@ -222,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 前台展示本地推送
|
||||
@@ -230,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 版本已过期")));
|
||||
|
||||
|
||||
///----------------------------------------------------
|
||||
@@ -304,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
|
||||
*
|
||||
@@ -333,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
|
||||
|
||||
Binary file not shown.
@@ -1,338 +1,372 @@
|
||||
var JPushPlugin = function () {}
|
||||
|
||||
// private plugin function
|
||||
|
||||
var JPushPlugin = function(){
|
||||
};
|
||||
JPushPlugin.prototype.receiveMessage = {}
|
||||
JPushPlugin.prototype.openNotification = {}
|
||||
JPushPlugin.prototype.receiveNotification = {}
|
||||
|
||||
//private plugin function
|
||||
|
||||
JPushPlugin.prototype.receiveMessage={}
|
||||
JPushPlugin.prototype.openNotification={}
|
||||
JPushPlugin.prototype.receiveNotification={}
|
||||
|
||||
|
||||
JPushPlugin.prototype.isPlatformIOS = function(){
|
||||
return device.platform == "iPhone" || device.platform == "iPad" || device.platform == "iPod touch" || device.platform == "iOS"
|
||||
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;
|
||||
}
|
||||
//public plugin function
|
||||
|
||||
JPushPlugin.prototype.startLogPageView = function(pageName){
|
||||
if(this.isPlatformIOS()){
|
||||
this.call_native( "startLogPageView",[pageName],null);
|
||||
}
|
||||
JPushPlugin.prototype.call_native = function (name, args, callback) {
|
||||
ret = cordova.exec(callback, this.error_callback, 'JPushPlugin', name, args)
|
||||
return ret
|
||||
}
|
||||
|
||||
JPushPlugin.prototype.stopLogPageView = function(pageName){
|
||||
if(this.isPlatformIOS()){
|
||||
this.call_native( "stopLogPageView",[pageName],null);
|
||||
}
|
||||
// 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.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);
|
||||
}
|
||||
}
|
||||
|
||||
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.getRegistrationID = function (callback) {
|
||||
try {
|
||||
var data = []
|
||||
this.call_native('getRegistrationID', [data], callback)
|
||||
} catch(exception) {
|
||||
console.log(exception)
|
||||
}
|
||||
}
|
||||
|
||||
JPushPlugin.prototype.setAlias = function(alias){
|
||||
try{
|
||||
this.call_native("setAlias",[alias],null);
|
||||
}
|
||||
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.setBadge = function(value){
|
||||
|
||||
if(this.isPlatformIOS()){
|
||||
try{
|
||||
this.call_native("setBadge",[value],null);
|
||||
}
|
||||
catch(exception){
|
||||
console.log(exception);
|
||||
}
|
||||
|
||||
}
|
||||
JPushPlugin.prototype.resumePush = function () {
|
||||
data = []
|
||||
this.call_native('resumePush', 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.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
|
||||
}
|
||||
}
|
||||
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.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.receiveMessageInAndroidCallback = function(data){
|
||||
try{
|
||||
console.log("JPushPlugin:receiveMessageInAndroidCallback");
|
||||
var bToObj = JSON.parse(data);
|
||||
this.receiveMessage=bToObj
|
||||
cordova.fireDocumentEvent('jpush.receiveMessage',null);
|
||||
//console.log(data);
|
||||
//var message = bToObj.message;
|
||||
//var extras = bToObj.extras;
|
||||
|
||||
//console.log(message);
|
||||
//console.log(extras['cn.jpush.android.MSG_ID']);
|
||||
//console.log(extras['cn.jpush.android.CONTENT_TYPE']);
|
||||
//console.log(extras['cn.jpush.android.EXTRA']);
|
||||
}
|
||||
catch(exception){
|
||||
console.log("JPushPlugin:pushCallback "+exception);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
JPushPlugin.prototype.openNotificationInAndroidCallback = function(data){
|
||||
try{
|
||||
console.log("JPushPlugin:openNotificationInAndroidCallback");
|
||||
var bToObj = JSON.parse(data);
|
||||
this.openNotification=bToObj;
|
||||
cordova.fireDocumentEvent('jpush.openNotification',null);
|
||||
|
||||
//console.log(data);
|
||||
//var bToObj = JSON.parse(data);
|
||||
//var alert = bToObj.alert;
|
||||
//var extras = bToObj.extras;
|
||||
//console.log(alert);
|
||||
|
||||
//console.log(extras['cn.jpush.android.MSG_ID']);
|
||||
//console.log(extras['app']);
|
||||
//console.log(extras['cn.jpush.android.NOTIFICATION_CONTENT_TITLE']);
|
||||
//console.log(extras['cn.jpush.android.EXTRA']);
|
||||
//console.log(extras['cn.jpush.android.PUSH_ID']);
|
||||
//console.log(extras['cn.jpush.android.NOTIFICATION_ID']);
|
||||
//console.log("JPushPlugin:openNotificationCallback is ready");
|
||||
}
|
||||
catch(exception){
|
||||
console.log(exception);
|
||||
}
|
||||
}
|
||||
JPushPlugin.prototype.receiveNotificationInAndroidCallback = function(data){
|
||||
try{
|
||||
console.log("JPushPlugin:receiveNotificationInAndroidCallback");
|
||||
var bToObj = JSON.parse(data);
|
||||
this.receiveNotification=bToObj;
|
||||
cordova.fireDocumentEvent('jpush.receiveNotification',null);
|
||||
|
||||
//console.log(data);
|
||||
//var bToObj = JSON.parse(data);
|
||||
//var alert = bToObj.alert;
|
||||
//var extras = bToObj.extras;
|
||||
//console.log(alert);
|
||||
|
||||
//console.log(extras['cn.jpush.android.MSG_ID']);
|
||||
//console.log(extras['app']);
|
||||
//console.log(extras['cn.jpush.android.NOTIFICATION_CONTENT_TITLE']);
|
||||
//console.log(extras['cn.jpush.android.EXTRA']);
|
||||
//console.log(extras['cn.jpush.android.PUSH_ID']);
|
||||
//console.log(extras['cn.jpush.android.NOTIFICATION_ID']);
|
||||
//console.log("JPushPlugin:openNotificationCallback is ready");
|
||||
}
|
||||
catch(exception){
|
||||
console.log(exception);
|
||||
}
|
||||
}
|
||||
//android single
|
||||
|
||||
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.stopPush = function(){
|
||||
data=[];
|
||||
this.call_native("stopPush",data,null);
|
||||
}
|
||||
|
||||
JPushPlugin.prototype.resumePush = function(){
|
||||
data=[]
|
||||
this.call_native("resumePush",data,null);
|
||||
|
||||
}
|
||||
JPushPlugin.prototype.setDebugMode = function(mode){
|
||||
if(device.platform == "Android") {
|
||||
this.call_native("setDebugMode",[mode],null);
|
||||
}
|
||||
}
|
||||
//setDebugMode
|
||||
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);
|
||||
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.setLatestNotificationNum = function(num){
|
||||
if(device.platform == "Android") {
|
||||
this.call_native("setLatestNotificationNum",[num],null);
|
||||
}
|
||||
JPushPlugin.prototype.setTags = function (tags) {
|
||||
try {
|
||||
this.call_native('setTags', tags, null)
|
||||
} catch(exception) {
|
||||
console.log(exception)
|
||||
}
|
||||
}
|
||||
|
||||
JPushPlugin.prototype.isPushStopped = function(callback){
|
||||
|
||||
data=[];
|
||||
this.call_native("isPushStopped",data,callback)
|
||||
|
||||
JPushPlugin.prototype.setAlias = function (alias) {
|
||||
try {
|
||||
this.call_native('setAlias', [alias], null)
|
||||
} catch(exception) {
|
||||
console.log(exception)
|
||||
}
|
||||
}
|
||||
|
||||
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.setBadge = function (value) {
|
||||
if (this.isPlatformIOS()) {
|
||||
try {
|
||||
this.call_native('setBadge', [value], null)
|
||||
} catch(exception) {
|
||||
console.log(exception)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
JPushPlugin.prototype.setDebugMode = function(mode){
|
||||
if(device.platform == "Android") {
|
||||
this.call_native("setDebugMode",[mode],null);
|
||||
}
|
||||
}
|
||||
JPushPlugin.prototype.addLocalNotification = function(builderId,content,title,notificaitonID,broadcastTime,extras){
|
||||
if(device.platform == "Android") {
|
||||
data=[builderId,content,title,notificaitonID,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.clearLocalNotifications = function(){
|
||||
if(device.platform == "Android") {
|
||||
data=[]
|
||||
this.call_native("clearLocalNotifications",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.reportNotificationOpened = function(msgID){
|
||||
if(device.platform == "Android") {
|
||||
|
||||
this.call_native("reportNotificationOpened",[msgID],null);
|
||||
}
|
||||
JPushPlugin.prototype.setDebugModeFromIos = function () {
|
||||
if (this.isPlatformIOS()) {
|
||||
var data = []
|
||||
this.call_native('setDebugModeFromIos', [data], null)
|
||||
}
|
||||
}
|
||||
|
||||
//iOS single
|
||||
|
||||
|
||||
if(!window.plugins){
|
||||
window.plugins = {};
|
||||
JPushPlugin.prototype.setLogOFF = function () {
|
||||
if (this.isPlatformIOS()) {
|
||||
var data = []
|
||||
this.call_native('setLogOFF', [data], null)
|
||||
}
|
||||
}
|
||||
|
||||
if(!window.plugins.jPushPlugin){
|
||||
window.plugins.jPushPlugin = new JPushPlugin();
|
||||
}
|
||||
JPushPlugin.prototype.setCrashLogON = function () {
|
||||
if (this.isPlatformIOS()) {
|
||||
var data = []
|
||||
this.call_native('crashLogON', [data], null)
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = new JPushPlugin();
|
||||
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.deleteLocalNotificationWithIdentifierKeyInIOS = function (
|
||||
identifierKey) {
|
||||
if (this.isPlatformIOS()) {
|
||||
var data = [identifierKey]
|
||||
this.call_native('deleteLocalNotificationWithIdentifierKey', data, null)
|
||||
}
|
||||
}
|
||||
|
||||
JPushPlugin.prototype.clearAllLocalNotifications = function () {
|
||||
if (this.isPlatformIOS()) {
|
||||
var data = []
|
||||
this.call_native('clearAllLocalNotifications', data, null)
|
||||
}
|
||||
}
|
||||
|
||||
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: 通知关闭。
|
||||
// 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
|
||||
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.setCustomPushNotificationBuilder = function () {
|
||||
if (device.platform == 'Android') {
|
||||
data = []
|
||||
this.call_native('setCustomPushNotificationBuilder', data, null)
|
||||
}
|
||||
}
|
||||
|
||||
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 {
|
||||
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 {
|
||||
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.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.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.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.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)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 用于在 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.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)
|
||||
}
|
||||
}
|
||||
|
||||
if (!window.plugins) {
|
||||
window.plugins = {}
|
||||
}
|
||||
|
||||
if (!window.plugins.jPushPlugin) {
|
||||
window.plugins.jPushPlugin = new JPushPlugin()
|
||||
}
|
||||
|
||||
module.exports = new JPushPlugin()
|
||||
|
||||
Reference in New Issue
Block a user