2016-01-21 15:15:48 +08:00
|
|
|
|
## JPush PhoneGap Plugin ##
|
2015-04-14 11:21:09 +08:00
|
|
|
|
|
2016-01-21 15:15:48 +08:00
|
|
|
|
jpush-phonegap-plugin 支持 iOS,Android 的推送插件。
|
2015-04-14 11:21:09 +08:00
|
|
|
|
|
2016-01-21 15:15:48 +08:00
|
|
|
|
**功能特性:**
|
|
|
|
|
>+ 发送推送通知
|
|
|
|
|
+ 发送推送自定义消息
|
|
|
|
|
+ 设置推送标签和别名
|
|
|
|
|
+ 设置角标(iOS)
|
|
|
|
|
|
|
|
|
|
*如需要 IM 功能插件,请关注[jmessage-phonegap-plugin](https://github.com/jpush/jmessage-phonegap-plugin)*
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## 安装 ##
|
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`,
|
|
|
|
|
然后再执行`cordova plugin add xxxxx`命令,不然有一些必须要的链接库需要手动添加
|
2016-03-04 15:20:45 +08:00
|
|
|
|
|
2013-10-18 15:32:05 +08:00
|
|
|
|
|
2015-04-14 11:21:09 +08:00
|
|
|
|
###Cordova CLI/Phonegap 安装 Android & iOS
|
|
|
|
|
|
2015-12-01 16:15:58 +08:00
|
|
|
|
1). 安装JPush PhoneGap Plugin。 有两种方法。
|
2015-04-14 11:21:09 +08:00
|
|
|
|
|
2015-12-01 16:13:51 +08:00
|
|
|
|
方法一: 在线安装
|
2015-12-01 16:14:52 +08:00
|
|
|
|
|
2015-12-01 15:40:16 +08:00
|
|
|
|
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
|
|
|
|
|
2015-12-01 15:40:16 +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
|
|
|
|
|
|
|
|
|
|
2015-12-01 16:15:58 +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
|
|
|
|
|
|
|
|
|
|
2015-12-01 16:15:58 +08:00
|
|
|
|
3). 在js中调用函数,初始化jpush sdk
|
2015-12-01 15:18:40 +08:00
|
|
|
|
|
2016-03-04 15:20:45 +08:00
|
|
|
|
window.plugins.jPushPlugin.init();
|
2015-12-01 16:15:58 +08:00
|
|
|
|
//由于phonegap插件采用了Lazy load的特性, 所以这里建议在js文件能执行的最开始就加
|
2013-10-18 11:14:33 +08:00
|
|
|
|
|
|
|
|
|
|
2015-04-14 09:58:44 +08:00
|
|
|
|
### Android 手工安装
|
2014-07-10 15:46:30 +08:00
|
|
|
|
|
2015-04-14 09:58:44 +08:00
|
|
|
|
[Android 手工安装文档地址](document/Android_handle_install.md)
|
2016-03-04 15:20:45 +08:00
|
|
|
|
|
2014-07-10 15:46:30 +08:00
|
|
|
|
|
2014-01-21 13:41:11 +08:00
|
|
|
|
### IOS手工安装
|
|
|
|
|
|
2015-04-14 09:58:44 +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
|
|
|
|
|
2015-12-01 15:40:16 +08:00
|
|
|
|
1. "$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
|
|
|
|
|
2014-07-25 10:06:06 +08:00
|
|
|
|
###关于'phonegap build'云服务
|
2015-04-14 11:21:09 +08:00
|
|
|
|
|
2014-07-25 10:06:06 +08:00
|
|
|
|
该项目基于cordova实现,目前无法使用'phonegap build'云服务进行打包,建议使用本地环境进行打包
|
2015-04-14 09:58:44 +08:00
|
|
|
|
|
2015-01-16 10:42:06 +08:00
|
|
|
|
### 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
|
|
|
|
|
|
2015-04-14 09:58:44 +08:00
|
|
|
|
具体的API请参考这里
|
2015-01-16 10:42:06 +08:00
|
|
|
|
|
2016-03-04 15:20:45 +08:00
|
|
|
|
#### iOS和android通用API简介
|
2015-01-16 10:42:06 +08:00
|
|
|
|
|
2015-04-14 13:08:41 +08:00
|
|
|
|
+ 停止与恢复推送服务 API
|
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)
|
|
|
|
|
|
|
|
|
|
|
2015-04-14 09:58:44 +08:00
|
|
|
|
+ 获取 RegistrationID API
|
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
|
|
|
|
|
2015-04-14 09:58:44 +08:00
|
|
|
|
+ 别名与标签 API
|
2016-03-04 15:20:45 +08:00
|
|
|
|
|
2015-04-14 09:58:44 +08:00
|
|
|
|
window.plugins.jPushPlugin.setTagsWithAlias(tags,alias)
|
|
|
|
|
window.plugins.jPushPlugin.setTags(tags)
|
|
|
|
|
window.plugins.jPushPlugin.setAlias(alias)
|
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
|
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
|
|
|
|
|
2015-04-14 09:58:44 +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
|
|
|
|
|
2015-04-14 15:11:21 +08:00
|
|
|
|
event - jpush.receiveMessage
|
|
|
|
|
//推荐使用事件的方式传递,但同时保留了receiveMessageIniOSCallback的回调函数,兼容以前的代码
|
2015-04-14 09:58:44 +08:00
|
|
|
|
window.plugins.jPushPlugin.receiveMessageIniOSCallback(data)
|
2016-03-04 15:20:45 +08:00
|
|
|
|
|
2015-04-14 09:58:44 +08:00
|
|
|
|
+ 页面的统计
|
2016-03-04 15:20:45 +08:00
|
|
|
|
|
2015-04-14 09:58:44 +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
|
|
|
|
|
2015-04-14 09:58:44 +08:00
|
|
|
|
+ 设置Badge
|
|
|
|
|
|
|
|
|
|
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-03-22 11:09:43 +08:00
|
|
|
|
window.plugins.JPushPlugin.addLocalNotificationForIOS(delayTime, content, badge, notificationID, extras)
|
|
|
|
|
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
|
|
|
|
|
2015-04-14 09:58:44 +08:00
|
|
|
|
window.plugins.jPushPlugin.setDebugModeFromIos ()
|
|
|
|
|
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
|
|
|
|
|
2015-04-14 09:58:44 +08:00
|
|
|
|
[iOS API详细说明](document/iOS_detail_api.md)
|
2015-04-10 11:11:26 +08:00
|
|
|
|
|
|
|
|
|
|
2016-03-04 15:20:45 +08:00
|
|
|
|
#### android API简介
|
|
|
|
|
|
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
|
|
|
|
|
2015-04-15 16:59:32 +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
|
|
|
|
|
2015-04-14 09:58:44 +08:00
|
|
|
|
+ 统计分析 API
|
2015-01-26 14:40:44 +08:00
|
|
|
|
|
2016-03-04 15:20:45 +08:00
|
|
|
|
window.plugins.jPushPlugin.setStatisticsOpen(boolean)
|
|
|
|
|
|
|
|
|
|
或在 MainActivity 中的 onPause() 和 onResume() 方法中分别调用
|
|
|
|
|
JPushInterface.onResume(this) 和 JPushInterface.onPause(this) 来启用统计分析功能,
|
|
|
|
|
如果使用这种方式启用统计分析功能,则window.plugins.jPushPlugin.setStatisticsOpen(boolean)
|
|
|
|
|
方法不再有效,建议不要同时使用。
|
|
|
|
|
|
2015-04-14 09:58:44 +08:00
|
|
|
|
+ 清除通知 API
|
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
|
|
|
|
|
2015-04-14 09:58:44 +08:00
|
|
|
|
+ 通知栏样式定制 API
|
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
|
|
|
|
|
2015-04-14 09:58:44 +08:00
|
|
|
|
+ 设置保留最近通知条数 API
|
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
|
|
|
|
|
2015-04-14 09:58:44 +08:00
|
|
|
|
+ 本地通知API
|
2016-03-04 15:20:45 +08:00
|
|
|
|
|
2015-04-14 09:58:44 +08:00
|
|
|
|
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)
|
2015-04-14 11:35:27 +08:00
|
|
|
|
|
2016-01-21 15:15:48 +08:00
|
|
|
|
###常见问题
|
|
|
|
|
|
2016-03-04 15:20:45 +08:00
|
|
|
|
####1. android
|
2016-01-21 15:15:48 +08:00
|
|
|
|
|
|
|
|
|
eclipse中phonegap工程import之后出现:`Type CallbackContext cannot be resolved to a type`
|
|
|
|
|
解决方案:eclipse中右键单击工程名,Build Path->Config Build Path->Projects->选中 工程名称-CordovaLib->点击 add
|
|
|
|
|
|
|
|
|
|
####2. iOS 设置/修改 APP_KEY
|
2016-03-04 15:20:45 +08:00
|
|
|
|
|
|
|
|
|
在PushConfig.plist 中修改。PushConfig.plist 其他值说明:
|
2016-01-21 15:15:48 +08:00
|
|
|
|
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-03-04 15:20:45 +08:00
|
|
|
|
[JPush官网文档](http://docs.jpush.io/)
|