2016-03-30 16:23:18 +08:00
|
|
|
|
## JPush PhoneGap/Cordova Plugin ##
|
2015-04-14 11:21:09 +08:00
|
|
|
|
|
2016-03-30 22:12:49 +08:00
|
|
|
|
JPush-PhoneGap-Plugin 支持 iOS, Android 的推送插件。
|
2015-04-14 11:21:09 +08:00
|
|
|
|
|
2016-01-21 15:15:48 +08:00
|
|
|
|
**功能特性:**
|
2016-03-30 16:23:18 +08:00
|
|
|
|
支持 iOS, Android 的极光推送插件。
|
2015-04-14 11:21:09 +08:00
|
|
|
|
|
2016-03-30 16:23:18 +08:00
|
|
|
|
### 功能特性
|
2016-03-30 22:12:49 +08:00
|
|
|
|
+ 发送推送通知
|
2016-01-21 15:15:48 +08:00
|
|
|
|
+ 发送推送自定义消息
|
|
|
|
|
+ 设置推送标签和别名
|
|
|
|
|
+ 设置角标(iOS)
|
|
|
|
|
|
2016-03-30 22:12:49 +08:00
|
|
|
|
*如需要 IM 功能插件,请关注 [jmessage-phonegap-plugin](https://github.com/jpush/jmessage-phonegap-plugin)*
|
2016-01-21 15:15:48 +08:00
|
|
|
|
|
|
|
|
|
## 安装 ##
|
2015-04-14 11:21:09 +08:00
|
|
|
|
###准备工作
|
|
|
|
|
|
2015-12-01 15:40:16 +08:00
|
|
|
|
1. cordova create 文件夹名字 包名 应用名字
|
2013-10-18 11:14:33 +08:00
|
|
|
|
|
2014-07-10 15:46:30 +08:00
|
|
|
|
cordova create Myproj com.myproj.jpush MyTestProj
|
2016-03-04 15:20:45 +08:00
|
|
|
|
|
2015-12-01 15:40:16 +08:00
|
|
|
|
2. 添加平台
|
2013-10-18 11:14:33 +08:00
|
|
|
|
|
2016-03-04 15:20:45 +08:00
|
|
|
|
cd Myproj
|
2014-07-10 15:46:30 +08:00
|
|
|
|
cordova platform add android
|
2015-01-19 16:37:44 +08:00
|
|
|
|
cordova platform add ios
|
2014-07-10 15:46:30 +08:00
|
|
|
|
|
2015-04-14 09:58:44 +08:00
|
|
|
|
ps:这里请注意iOS平台,必须先执行 `cordova platform add ios`,
|
2016-03-30 22:12:49 +08:00
|
|
|
|
然后再执行 `cordova plugin add xxxxx` 命令,不然有一些必须要的链接库需要手动添加
|
2016-03-04 15:20:45 +08:00
|
|
|
|
|
2013-10-18 15:32:05 +08:00
|
|
|
|
|
2016-03-30 22:12:49 +08:00
|
|
|
|
###Cordova CLI / PhoneGap 安装 Android & iOS
|
2015-04-14 11:21:09 +08:00
|
|
|
|
|
2016-03-30 22:12:49 +08:00
|
|
|
|
1). 安装 JPush PhoneGap Plugin, 有两种方法:
|
2015-04-14 11:21:09 +08:00
|
|
|
|
|
2016-03-30 22:12:49 +08:00
|
|
|
|
方法一:在线安装
|
2015-12-01 16:14:52 +08:00
|
|
|
|
|
2016-04-08 10:18:34 +08:00
|
|
|
|
通过 cordova plugins 安装,要求 phonegap/cordova CLI 5.0+ (current stable v2.1.1)
|
|
|
|
|
|
|
|
|
|
cordova plugin add jpush-phonegap-plugin --variable API_KEY=your_jpush_appkey
|
|
|
|
|
|
|
|
|
|
直接通过 url 安装(unstable)
|
|
|
|
|
|
|
|
|
|
cordova plugin add https://github.com/jpush/jpush-phonegap-plugin.git --variable API_KEY=your_jpush_appkey
|
2015-04-14 11:21:09 +08:00
|
|
|
|
|
2015-12-01 16:13:51 +08:00
|
|
|
|
方法二:下载到本地再安装
|
2015-12-01 16:14:52 +08:00
|
|
|
|
|
2016-03-30 22:12:49 +08:00
|
|
|
|
使用 git 命令将 JPush PhoneGap 插件下载的本地,将这个目录标记为 `$JPUSH_PLUGIN_DIR`
|
2015-12-01 16:06:41 +08:00
|
|
|
|
|
2015-12-01 15:40:16 +08:00
|
|
|
|
git clone https://github.com/jpush/jpush-phonegap-plugin.git
|
|
|
|
|
cordova plugin add $JPUSH_PLUGIN_DIR --variable API_KEY=your_jpush_appkey
|
2015-08-18 13:51:26 +08:00
|
|
|
|
|
2015-12-01 15:18:40 +08:00
|
|
|
|
|
2016-03-30 22:12:49 +08:00
|
|
|
|
2). 安装 org.apache.cordova.device
|
2015-12-01 16:14:52 +08:00
|
|
|
|
|
2015-12-01 16:15:58 +08:00
|
|
|
|
cordova plugin add org.apache.cordova.device
|
2015-12-01 15:18:40 +08:00
|
|
|
|
|
|
|
|
|
|
2016-03-30 22:12:49 +08:00
|
|
|
|
3). 在 js 中调用函数,初始化 JPush SDK
|
2015-12-01 15:18:40 +08:00
|
|
|
|
|
2016-03-30 22:12:49 +08:00
|
|
|
|
//由于 PhoneGap 插件采用了 Lazy load 的特性,所以建议在 js 文件能执行的最开始就添加
|
2016-03-04 15:20:45 +08:00
|
|
|
|
window.plugins.jPushPlugin.init();
|
2013-10-18 11:14:33 +08:00
|
|
|
|
|
|
|
|
|
|
2016-04-09 18:06:11 +08:00
|
|
|
|
### Android 手动安装
|
2014-07-10 15:46:30 +08:00
|
|
|
|
|
2016-04-09 18:06:11 +08:00
|
|
|
|
[Android 手动安装文档地址](document/Android_handle_install.md)
|
2016-03-04 15:20:45 +08:00
|
|
|
|
|
2014-07-10 15:46:30 +08:00
|
|
|
|
|
2016-04-09 18:06:11 +08:00
|
|
|
|
### iOS 手动安装
|
2014-01-21 13:41:11 +08:00
|
|
|
|
|
2016-04-09 18:06:11 +08:00
|
|
|
|
[IOS手动安装文档地址](document/iOS_handle_install.md)
|
2014-07-10 15:46:30 +08:00
|
|
|
|
|
|
|
|
|
|
2014-01-21 14:19:32 +08:00
|
|
|
|
###示例
|
2013-10-18 11:14:33 +08:00
|
|
|
|
|
2016-03-30 22:12:49 +08:00
|
|
|
|
"$JPUSH_PLUGIN_DIR/example"文件夹内找到并拷贝以下文件
|
2014-07-10 15:46:30 +08:00
|
|
|
|
|
2015-04-16 14:56:06 +08:00
|
|
|
|
src/example/index.html to www/index.html
|
|
|
|
|
src/example/css/* to www/css
|
|
|
|
|
src/example/js/* to www/js
|
2014-07-10 15:46:30 +08:00
|
|
|
|
|
2016-03-30 22:12:49 +08:00
|
|
|
|
###关于'PhoneGap build'云服务
|
|
|
|
|
|
|
|
|
|
该项目基于 cordova 实现,目前无法使用 'PhoneGap build' 云服务进行打包,建议使用本地环境进行打包
|
|
|
|
|
|
|
|
|
|
### API 说明
|
|
|
|
|
|
|
|
|
|
插件的 API 集中在 JPushPlugin.js 文件中,该文件的具体位置如下:
|
2015-04-14 11:21:09 +08:00
|
|
|
|
|
2016-03-30 22:12:49 +08:00
|
|
|
|
Android:
|
2015-04-14 09:58:44 +08:00
|
|
|
|
|
2016-03-30 22:12:49 +08:00
|
|
|
|
[Project]/assets/www/plugins/cn.jpush.phonegap.JPushPlugin/www
|
2015-01-16 10:42:06 +08:00
|
|
|
|
|
2016-03-30 22:12:49 +08:00
|
|
|
|
iOS:
|
2015-01-16 10:42:06 +08:00
|
|
|
|
|
2016-03-30 22:12:49 +08:00
|
|
|
|
[Project]/www/plugins/cn.jpush.phonegap.JPushPlugin/www
|
2015-01-16 10:42:06 +08:00
|
|
|
|
|
2016-03-30 22:12:49 +08:00
|
|
|
|
具体的 API 请参考下面:
|
2015-01-16 10:42:06 +08:00
|
|
|
|
|
2016-03-30 22:12:49 +08:00
|
|
|
|
#### iOS 和 Android 通用 API 简介
|
2015-01-16 10:42:06 +08:00
|
|
|
|
|
2016-03-30 22:12:49 +08:00
|
|
|
|
+ 停止与恢复推送服务
|
2016-03-04 15:20:45 +08:00
|
|
|
|
|
2015-04-14 13:08:41 +08:00
|
|
|
|
window.plugins.jPushPlugin.init()
|
|
|
|
|
window.plugins.jPushPlugin.stopPush()
|
|
|
|
|
window.plugins.jPushPlugin.resumePush()
|
|
|
|
|
window.plugins.jPushPlugin.isPushStopped(callback)
|
|
|
|
|
|
2016-03-30 22:12:49 +08:00
|
|
|
|
+ 获取 RegistrationID
|
2015-01-16 15:02:06 +08:00
|
|
|
|
|
2015-04-14 09:58:44 +08:00
|
|
|
|
window.plugins.jPushPlugin.getRegistrationID(callback)
|
2016-03-04 15:20:45 +08:00
|
|
|
|
|
2016-03-30 22:12:49 +08:00
|
|
|
|
+ 别名与标签
|
2016-03-04 15:20:45 +08:00
|
|
|
|
|
2016-03-30 22:12:49 +08:00
|
|
|
|
window.plugins.jPushPlugin.setTagsWithAlias(tags, alias)
|
2015-04-14 09:58:44 +08:00
|
|
|
|
window.plugins.jPushPlugin.setTags(tags)
|
|
|
|
|
window.plugins.jPushPlugin.setAlias(alias)
|
2016-03-30 22:12:49 +08:00
|
|
|
|
|
2016-04-11 15:21:59 +08:00
|
|
|
|
event - jpush.setTagsWithAlias //三个方法都是触发该回调事件
|
|
|
|
|
|
2015-06-09 17:31:57 +08:00
|
|
|
|
+ 获取点击通知内容
|
2016-03-04 15:20:45 +08:00
|
|
|
|
|
2015-04-15 16:59:32 +08:00
|
|
|
|
event - jpush.openNotification
|
2016-03-30 22:12:49 +08:00
|
|
|
|
|
2015-06-09 17:31:57 +08:00
|
|
|
|
+ 获取通知内容
|
2016-03-04 15:20:45 +08:00
|
|
|
|
|
2015-06-09 17:31:57 +08:00
|
|
|
|
event - jpush.receiveNotification
|
2015-04-15 16:59:32 +08:00
|
|
|
|
|
|
|
|
|
+ 获取自定义消息推送内容
|
|
|
|
|
|
|
|
|
|
event - jpush.receiveMessage
|
|
|
|
|
|
2015-01-16 15:02:06 +08:00
|
|
|
|
|
2016-03-30 22:12:49 +08:00
|
|
|
|
[通用 API 详细说明](document/Common_detail_api.md)
|
2015-01-26 14:30:28 +08:00
|
|
|
|
|
2015-04-14 09:58:44 +08:00
|
|
|
|
#### iOS API简介
|
2015-01-26 14:30:28 +08:00
|
|
|
|
|
2015-04-14 09:58:44 +08:00
|
|
|
|
+ 获取自定义消息推送内容
|
2015-04-14 13:08:41 +08:00
|
|
|
|
|
2016-03-30 22:12:49 +08:00
|
|
|
|
//推荐使用事件的方式传递,但同时保留了 receiveMessageIniOSCallback 的回调函数,兼容以前的代码
|
2015-04-14 09:58:44 +08:00
|
|
|
|
window.plugins.jPushPlugin.receiveMessageIniOSCallback(data)
|
2016-03-04 15:20:45 +08:00
|
|
|
|
|
2016-04-11 15:21:59 +08:00
|
|
|
|
event - jpush.receiveMessage
|
|
|
|
|
|
2015-04-14 09:58:44 +08:00
|
|
|
|
+ 页面的统计
|
2016-03-04 15:20:45 +08:00
|
|
|
|
|
2016-03-30 22:12:49 +08:00
|
|
|
|
window.plugins.jPushPlugin.startLogPageView(pageName)
|
|
|
|
|
window.plugins.jPushPlugin.stopLogPageView(pageName)
|
|
|
|
|
window.plugins.jPushPlugin.beginLogPageView(pageName, duration)
|
2016-03-22 11:09:43 +08:00
|
|
|
|
|
2016-03-30 22:12:49 +08:00
|
|
|
|
+ 设置 Badge
|
2015-04-14 09:58:44 +08:00
|
|
|
|
|
|
|
|
|
window.plugins.jPushPlugin.setBadge(value)
|
|
|
|
|
window.plugins.jPushPlugin.resetBadge()
|
|
|
|
|
window.plugins.jPushPlugin.setApplicationIconBadgeNumber(badge)
|
2016-03-22 11:09:43 +08:00
|
|
|
|
window.plugins.JPushPlugin.getApplicationIconBadgeNumber(callback)
|
|
|
|
|
|
2015-04-14 09:58:44 +08:00
|
|
|
|
+ 本地通知
|
2015-04-14 11:35:27 +08:00
|
|
|
|
|
2016-04-11 15:21:59 +08:00
|
|
|
|
window.plugins.JPushPlugin.addLocalNotificationForIOS(delayTime, content,
|
|
|
|
|
badge, notificationID, extras)
|
2016-03-22 11:09:43 +08:00
|
|
|
|
window.plugins.JPushPlugin.deleteLocalNotificationWithIdentifierKeyInIOS()
|
|
|
|
|
window.plugins.JPushPlugin.clearAllLocalNotifications()
|
2016-03-04 15:20:45 +08:00
|
|
|
|
|
2015-04-14 09:58:44 +08:00
|
|
|
|
+ 日志等级设置
|
2016-03-04 15:20:45 +08:00
|
|
|
|
|
2016-03-30 22:12:49 +08:00
|
|
|
|
window.plugins.jPushPlugin.setDebugModeFromIos()
|
2015-04-14 09:58:44 +08:00
|
|
|
|
window.plugins.jPushPlugin.setLogOFF()
|
2016-03-22 11:09:43 +08:00
|
|
|
|
window.plugins.JPushPlugin.setCrashLogON()
|
|
|
|
|
|
|
|
|
|
+ 地理位置上报
|
2016-03-04 15:20:45 +08:00
|
|
|
|
|
2016-03-22 11:09:43 +08:00
|
|
|
|
window.plugins.JPushPlugin.setLocation(latitude, longitude)
|
2016-03-04 15:20:45 +08:00
|
|
|
|
|
2016-03-30 22:12:49 +08:00
|
|
|
|
[iOS API 详细说明](document/iOS_detail_api.md)
|
2015-04-10 11:11:26 +08:00
|
|
|
|
|
|
|
|
|
|
2016-03-30 22:12:49 +08:00
|
|
|
|
#### Android API简介
|
2016-03-04 15:20:45 +08:00
|
|
|
|
|
2015-04-14 09:58:44 +08:00
|
|
|
|
+ 获取集成日志
|
2016-03-30 22:12:49 +08:00
|
|
|
|
|
2015-04-14 09:58:44 +08:00
|
|
|
|
window.plugins.jPushPlugin.setDebugMode(mode)
|
2015-01-27 15:40:46 +08:00
|
|
|
|
|
2015-06-09 17:31:57 +08:00
|
|
|
|
+ 接收推送消息和点击通知
|
2016-03-04 15:20:45 +08:00
|
|
|
|
|
2016-03-30 22:12:49 +08:00
|
|
|
|
//下面这两个 API 是兼容旧有的代码
|
2015-04-14 09:58:44 +08:00
|
|
|
|
window.plugins.jPushPlugin.receiveMessageInAndroidCallback(data)
|
|
|
|
|
window.plugins.jPushPlugin.openNotificationInAndroidCallback(data)
|
2015-01-27 15:40:46 +08:00
|
|
|
|
|
2016-03-30 22:12:49 +08:00
|
|
|
|
+ 统计分析
|
2015-01-26 14:40:44 +08:00
|
|
|
|
|
2016-03-04 15:20:45 +08:00
|
|
|
|
window.plugins.jPushPlugin.setStatisticsOpen(boolean)
|
|
|
|
|
|
|
|
|
|
或在 MainActivity 中的 onPause() 和 onResume() 方法中分别调用
|
2016-03-30 22:12:49 +08:00
|
|
|
|
JPushInterface.onPause(this) 和 JPushInterface.onResume(this) 来启用统计分析功能,
|
|
|
|
|
如果使用这种方式启用统计分析功能,则 window.plugins.jPushPlugin.setStatisticsOpen(boolean)
|
2016-03-04 15:20:45 +08:00
|
|
|
|
方法不再有效,建议不要同时使用。
|
|
|
|
|
|
2016-03-30 22:12:49 +08:00
|
|
|
|
+ 清除通知
|
2015-01-26 14:40:44 +08:00
|
|
|
|
|
2015-04-14 09:58:44 +08:00
|
|
|
|
window.plugins.jPushPlugin.clearAllNotification()
|
2015-01-26 14:40:44 +08:00
|
|
|
|
|
2016-03-30 22:12:49 +08:00
|
|
|
|
+ 通知栏样式定制
|
2015-01-16 10:42:06 +08:00
|
|
|
|
|
2015-04-14 09:58:44 +08:00
|
|
|
|
window.plugins.jPushPlugin.setBasicPushNotificationBuilder = function()
|
|
|
|
|
window.plugins.jPushPlugin.setCustomPushNotificationBuilder = function()
|
2015-03-25 16:11:04 +08:00
|
|
|
|
|
2016-03-30 22:12:49 +08:00
|
|
|
|
+ 设置保留最近通知条数
|
2016-03-04 15:20:45 +08:00
|
|
|
|
|
2015-04-14 09:58:44 +08:00
|
|
|
|
window.plugins.jPushPlugin.setLatestNotificationNum(num)
|
2016-03-04 15:20:45 +08:00
|
|
|
|
|
2016-03-30 22:12:49 +08:00
|
|
|
|
+ 本地通知
|
2016-03-04 15:20:45 +08:00
|
|
|
|
|
2016-03-30 22:12:49 +08:00
|
|
|
|
window.plugins.jPushPlugin.addLocalNotification(builderId, content,
|
|
|
|
|
title, notificaitonID, broadcastTime, extras)
|
2015-04-14 09:58:44 +08:00
|
|
|
|
window.plugins.jPushPlugin.removeLocalNotification(notificationID)
|
|
|
|
|
window.plugins.jPushPlugin.clearLocalNotifications()
|
|
|
|
|
|
2016-03-30 22:12:49 +08:00
|
|
|
|
[Android API 详细说明](document/Android_detail_api.md)
|
2015-04-14 11:35:27 +08:00
|
|
|
|
|
2016-01-21 15:15:48 +08:00
|
|
|
|
###常见问题
|
|
|
|
|
|
2016-03-30 22:12:49 +08:00
|
|
|
|
####1. Android
|
2016-01-21 15:15:48 +08:00
|
|
|
|
|
2016-03-30 22:12:49 +08:00
|
|
|
|
eclipse 中 PhoneGap 工程 import 之后出现:`Type CallbackContext cannot be resolved to a type`
|
|
|
|
|
解决方案:eclipse 中右键单击工程名,Build Path -> Config Build Path -> Projects -> 选中工程名称 -> CordovaLib -> 点击 add
|
2016-01-21 15:15:48 +08:00
|
|
|
|
|
2016-03-30 22:12:49 +08:00
|
|
|
|
####2. iOS 设置 / 修改 APP_KEY
|
2016-03-04 15:20:45 +08:00
|
|
|
|
|
2016-03-30 22:12:49 +08:00
|
|
|
|
在 PushConfig.plist 中修改。
|
|
|
|
|
PushConfig.plist 其他值说明:
|
|
|
|
|
CHANNEL: 渠道标识
|
|
|
|
|
IsProduction: 是否生产环境(暂未启用)
|
2016-03-04 15:20:45 +08:00
|
|
|
|
|
2016-01-21 15:15:48 +08:00
|
|
|
|
|
2015-04-14 11:35:27 +08:00
|
|
|
|
###更多
|
2016-04-11 15:21:59 +08:00
|
|
|
|
[JPush 官网文档](http://docs.jpush.io/)
|