2016-03-30 16:23:18 +08:00
|
|
|
|
## JPush PhoneGap/Cordova Plugin ##
|
2015-04-14 11:21:09 +08:00
|
|
|
|
|
2016-04-20 17:22:38 +08:00
|
|
|
|
[![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/jpush/jpush-phonegap-plugin)
|
|
|
|
|
[![release](https://img.shields.io/badge/release-2.1.3-blue.svg)](https://github.com/jpush/jpush-phonegap-plugin/releases)
|
|
|
|
|
[![platforms](https://img.shields.io/badge/platforms-iOS%7CAndroid-lightgrey.svg)](https://github.com/jpush/jpush-phonegap-plugin-plugin)
|
|
|
|
|
[![weibo](https://img.shields.io/badge/weibo-JPush-blue.svg)](http://weibo.com/jpush?refer_flag=1001030101_&is_all=1)
|
|
|
|
|
|
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-04-20 17:22:38 +08:00
|
|
|
|
+ 发送推送通知。
|
|
|
|
|
+ 发送推送自定义消息。
|
|
|
|
|
+ 设置推送标签和别名。
|
|
|
|
|
+ 设置角标(iOS)。
|
2016-01-21 15:15:48 +08:00
|
|
|
|
|
2016-04-20 17:22:38 +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-18 15:42:11 +08:00
|
|
|
|
通过 cordova plugins 安装,要求 phonegap/cordova CLI 5.0+
|
2016-04-08 10:18:34 +08:00
|
|
|
|
|
|
|
|
|
cordova plugin add jpush-phonegap-plugin --variable API_KEY=your_jpush_appkey
|
|
|
|
|
|
2016-04-18 15:42:11 +08:00
|
|
|
|
直接通过 url 安装
|
2016-04-08 10:18:34 +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
|
|
|
|
|
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-20 09:59:04 +08:00
|
|
|
|
[Android 手动安装文档地址](API/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-20 09:59:04 +08:00
|
|
|
|
[IOS 手动安装文档地址](API/iOS_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' 云服务进行打包,建议使用本地环境进行打包
|
|
|
|
|
|
2016-04-18 19:01:50 +08:00
|
|
|
|
## API 说明
|
2016-03-30 22:12:49 +08:00
|
|
|
|
|
|
|
|
|
插件的 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-04-18 19:01:50 +08:00
|
|
|
|
### 具体的 API 请参考:
|
2015-01-16 10:42:06 +08:00
|
|
|
|
|
2016-04-18 19:01:50 +08:00
|
|
|
|
- [公共 API](https://github.com/jpush/jpush-phonegap-plugin/blob/dev/API/Common_detail_api.md)
|
2015-01-16 10:42:06 +08:00
|
|
|
|
|
2016-04-18 19:01:50 +08:00
|
|
|
|
- [iOS API](https://github.com/jpush/jpush-phonegap-plugin/blob/dev/API/iOS%20API.md)
|
2016-03-04 15:20:45 +08:00
|
|
|
|
|
2016-04-18 19:01:50 +08:00
|
|
|
|
- [Android API](https://github.com/jpush/jpush-phonegap-plugin/blob/dev/API/Android_detail_api.md)
|
2015-04-14 13:08:41 +08:00
|
|
|
|
|
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-04-20 17:22:38 +08:00
|
|
|
|
####2. iOS
|
2016-04-18 19:01:50 +08:00
|
|
|
|
|
|
|
|
|
- 设置 / 修改 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-04-18 19:01:50 +08:00
|
|
|
|
- 收不到推送
|
|
|
|
|
|
|
|
|
|
请首先按照正确方式再次配置证书、描述文件
|
|
|
|
|
[iOS 证书 设置指南](http://docs.jpush.io/client/ios_tutorials/#ios_1)
|
|
|
|
|
|
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/)
|