mirror of
https://github.com/jpush/jpush-phonegap-plugin.git
synced 2026-04-19 00:03:45 +08:00
Compare commits
11 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 8d24ce7c48 | |||
| 280846779d | |||
| 1ba048ee1b | |||
| e4500dd513 | |||
| a511072101 | |||
| 851ff1f23b | |||
| 5cf5bd39d1 | |||
| 07bb05f337 | |||
| ceeb2fc7cf | |||
| 1eccd58059 | |||
| be6dbf4fe6 |
@@ -7,70 +7,47 @@
|
||||
[](http://weibo.com/jpush?refer_flag=1001030101_&is_all=1)
|
||||
|
||||
支持 iOS, Android 的 Cordova 推送插件。
|
||||
> 如需要 IM 功能的插件,可关注 [jmessage-phonegap-plugin](https://github.com/jpush/jmessage-phonegap-plugin)。
|
||||
|
||||
## 功能特性
|
||||
+ 发送推送通知。
|
||||
+ 发送推送自定义消息。
|
||||
+ 设置推送标签和别名。
|
||||
+ 设置角标(iOS)。
|
||||
## 集成步骤
|
||||
|
||||
*如需要 IM 功能插件,请关注 [jmessage-phonegap-plugin](https://github.com/jpush/jmessage-phonegap-plugin)*。
|
||||
|
||||
## 安装
|
||||
### 准备工作
|
||||
|
||||
1. cordova create 文件夹名字 包名 应用名字
|
||||
|
||||
cordova create Myproj com.myproj.jpush MyTestProj
|
||||
|
||||
2. 添加平台:
|
||||
|
||||
cd Myproj
|
||||
cordova platform add android
|
||||
cordova platform add ios
|
||||
|
||||
ps: 这里请注意iOS平台,必须先执行 cordova platform add ios,
|
||||
然后再执行 cordova plugin add xxxxx 命令,不然有一些必须要的链接库需要手动添加。
|
||||
|
||||
|
||||
### 集成步骤(Android & iOS)
|
||||
|
||||
#### 1.首先安装 cordova device 插件
|
||||
### 1.首先安装 cordova device 插件
|
||||
|
||||
cordova plugin add cordova-plugin-device
|
||||
|
||||
#### 2.安装 JPush PhoneGap Plugin
|
||||
### 2.安装 JPush PhoneGap Plugin
|
||||
安装 JPush PhoneGap Plugin 有两种方法:
|
||||
|
||||
方法一:在线安装
|
||||
|
||||
通过 cordova plugins 安装,要求 phonegap/cordova CLI 5.0+:
|
||||
通过 Cordova plugins 安装,要求 PhoneGap/Cordova CLI 5.0+:
|
||||
|
||||
cordova plugin add jpush-phonegap-plugin --variable API_KEY=your_jpush_appkey
|
||||
|
||||
直接通过 url 安装:
|
||||
直接通过 url 安装:
|
||||
|
||||
cordova plugin add https://github.com/jpush/jpush-phonegap-plugin.git --variable API_KEY=your_jpush_appkey
|
||||
|
||||
方法二:下载到本地再安装
|
||||
|
||||
使用 git 命令将 JPush PhoneGap 插件下载的本地,目录标记为 $JPUSH_PLUGIN_DIR。
|
||||
使用 git 命令将 JPush PhoneGap 插件下载的本地,目录标记为 $JPUSH_PLUGIN_DIR:
|
||||
|
||||
git clone https://github.com/jpush/jpush-phonegap-plugin.git
|
||||
|
||||
cordova plugin add $JPUSH_PLUGIN_DIR --variable API_KEY=your_jpush_appkey
|
||||
|
||||
[Android 手动安装文档地址](/doc/Android_handle_install.md)
|
||||
- [Android 手动安装文档地址](/doc/Android_handle_install.md)。
|
||||
|
||||
[IOS 手动安装文档地址](/doc/iOS_install.md)
|
||||
- [iOS 手动安装文档地址](/doc/iOS_install.md)。
|
||||
|
||||
#### 3.在 js 中调用函数,初始化 JPush
|
||||
### 3.在 js 中调用函数,初始化 JPush
|
||||
|
||||
//由于 PhoneGap 插件采用了 Lazy load 的特性,所以建议在 js 文件能执行的最开始就添加
|
||||
//由于 PhoneGap 插件采用了 lazy load 的特性,所以建议在 js 文件能执行的最开始就添加。
|
||||
window.plugins.jPushPlugin.init();
|
||||
|
||||
|
||||
## Demo
|
||||
插件中包含示例 Demo。若想参考,可以在 $JPUSH_PLUGIN_DIR/example 文件夹内找到并拷贝以下文件:
|
||||
插件项目中包含一个简单的 Demo。若想参考,可以在 /example 文件夹内找到并拷贝以下文件:
|
||||
|
||||
src/example/index.html -> www/index.html
|
||||
src/example/css/* -> www/css
|
||||
@@ -78,57 +55,51 @@
|
||||
|
||||
## 关于 PhoneGap build 云服务
|
||||
|
||||
该项目基于 cordova 实现,目前无法使用 PhoneGap build 云服务进行打包,建议使用本地环境进行打包。
|
||||
该项目基于 Cordova 实现,目前无法使用 PhoneGap build 云服务进行打包,建议使用本地环境进行打包。
|
||||
|
||||
## API 说明
|
||||
|
||||
插件的 API 集中在 JPushPlugin.js 文件中,该文件的具体位置如下:
|
||||
|
||||
Android:
|
||||
|
||||
插件的 API 在 JPushPlugin.js 文件中,该文件的具体位置如下:
|
||||
### Android
|
||||
[Project]/assets/www/plugins/cn.jpush.phonegap.JPushPlugin/www
|
||||
|
||||
iOS:
|
||||
|
||||
### iOS
|
||||
[Project]/www/plugins/cn.jpush.phonegap.JPushPlugin/www
|
||||
|
||||
### 具体的 API 请参考:
|
||||
|
||||
- [公共 API](/doc/Common_detail_api.md)
|
||||
- [公共 API](/doc/Common_detail_api.md)。
|
||||
|
||||
- [iOS API](/doc/iOS_API.md)
|
||||
- [iOS API](/doc/iOS_API.md)。
|
||||
|
||||
- [Android API](/doc/Android_detail_api.md)
|
||||
- [Android API](/doc/Android_detail_api.md)。
|
||||
|
||||
|
||||
## 常见问题
|
||||
|
||||
若要使用 CLI 来编译项目,注意使用 cordova compile 而不是 cordova build,因为 cordova build 会清除对插件文件的修改。
|
||||
具体 cordova CLI 用法可参考[cordova CLI 官方文档](https://cordova.apache.org/docs/en/latest/reference/cordova-cli/index.html)。
|
||||
若要使用 CLI 来编译项目,注意应使用 cordova compile 而不是 cordova build 命令,因为 cordova build 会清除对插件文件的修改。
|
||||
Cordova CLI 的具体用法可参考 [Cordova CLI 官方文档](https://cordova.apache.org/docs/en/latest/reference/cordova-cli/index.html)。
|
||||
|
||||
### 1. Android
|
||||
|
||||
eclipse 中 import PhoneGap 工程之后出现:`Type CallbackContext cannot be resolved to a type`。
|
||||
Eclipse 中 import PhoneGap 工程之后出现:*Type CallbackContext cannot be resolved to a type*。
|
||||
|
||||
解决方案:eclipse 中右键单击工程名,Build Path -> Config Build Path -> Projects -> 选中工程名称 -> CordovaLib -> 点击 add。
|
||||
解决方案:Eclipse 中右键单击工程名,Build Path -> Config Build Path -> Projects -> 选中工程名称 -> CordovaLib -> 点击 add。
|
||||
|
||||
### 2. iOS
|
||||
|
||||
- 收不到推送:
|
||||
|
||||
请首先按照正确方式再次配置证书、描述文件
|
||||
[iOS 证书设置指南](http://docs.jpush.io/client/ios_tutorials/#ios_1)
|
||||
- 收不到推送:
|
||||
请首先按照正确方式再次配置证书、描述文件,具体可参考 [iOS 证书设置指南](http://docs.jpush.io/client/ios_tutorials/#ios_1)。
|
||||
|
||||
- 设置 PushConfig.plist:
|
||||
|
||||
- APP_KEY:应用标识
|
||||
- CHANNEL:渠道标识
|
||||
- IsProduction:是否生产环境
|
||||
- IsIDFA:是否使用 IDFA 启动 sdk
|
||||
- APP_KEY:应用标识。
|
||||
- CHANNEL:渠道标识。
|
||||
- IsProduction:是否生产环境。
|
||||
- IsIDFA:是否使用 IDFA 启动 SDK。
|
||||
|
||||
|
||||
|
||||
## 更多
|
||||
[JPush 官网文档](http://docs.jpush.io/)
|
||||
[JPush 官网文档](http://docs.jpush.io/)。
|
||||
|
||||
如有问题可访问[极光社区](http://community.jpush.cn/)
|
||||
如有问题可访问[极光社区](http://community.jpush.cn/)。
|
||||
|
||||
+2
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "jpush-phonegap-plugin",
|
||||
"version": "2.1.7",
|
||||
"version": "2.2.0",
|
||||
"description": "JPush for cordova plugin",
|
||||
"cordova": {
|
||||
"id": "cn.jpush.phonegap.JPushPlugin",
|
||||
@@ -16,6 +16,7 @@
|
||||
"keywords": [
|
||||
"JPush",
|
||||
"push",
|
||||
"Push",
|
||||
"ecosystem:cordova",
|
||||
"cordova-ios",
|
||||
"cordova-android"
|
||||
|
||||
+8
-8
@@ -2,7 +2,7 @@
|
||||
<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.7">
|
||||
version="2.2.0">
|
||||
|
||||
<name>JPush Plugin</name>
|
||||
<description>JPush for cordova plugin</description>
|
||||
@@ -31,7 +31,7 @@
|
||||
<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.6.a" framework="true" />
|
||||
<source-file src="src/ios/lib/jpush-ios-2.1.7.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" />
|
||||
@@ -174,12 +174,12 @@
|
||||
<meta-data android:name="JPUSH_APPKEY" android:value="$API_KEY"/>
|
||||
</config-file>
|
||||
|
||||
<source-file src="src/android/jpush-android-2.1.3.jar" target-dir="libs"/>
|
||||
<source-file src="src/android/armeabi/libjpush213.so" target-dir="libs/armeabi"/>
|
||||
<source-file src="src/android/armeabi-v7a/libjpush213.so" target-dir="libs/armeabi-v7a"/>
|
||||
<source-file src="src/android/arm64-v8a/libjpush213.so" target-dir="libs/arm64-v8a"/>
|
||||
<source-file src="src/android/x86/libjpush213.so" target-dir="libs/x86"/>
|
||||
<source-file src="src/android/x86_64/libjpush213.so" target-dir="libs/x86_64"/>
|
||||
<source-file src="src/android/jpush-android-2.1.5.jar" target-dir="libs"/>
|
||||
<source-file src="src/android/armeabi/libjpush215.so" target-dir="libs/armeabi"/>
|
||||
<source-file src="src/android/armeabi-v7a/libjpush215.so" target-dir="libs/armeabi-v7a"/>
|
||||
<source-file src="src/android/arm64-v8a/libjpush215.so" target-dir="libs/arm64-v8a"/>
|
||||
<source-file src="src/android/x86/libjpush215.so" target-dir="libs/x86"/>
|
||||
<source-file src="src/android/x86_64/libjpush215.so" target-dir="libs/x86_64"/>
|
||||
|
||||
<!--<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"/>
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -16,7 +16,7 @@ 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 *_luanchOptions = nil;
|
||||
static NSDictionary *_launchOptions = nil;
|
||||
|
||||
@implementation JPushPlugin
|
||||
|
||||
@@ -92,8 +92,8 @@ static NSDictionary *_luanchOptions = nil;
|
||||
name:kJPushPluginReceiveNotification
|
||||
object:nil];
|
||||
|
||||
if (_luanchOptions) {
|
||||
NSDictionary *userInfo = [_luanchOptions
|
||||
if (_launchOptions) {
|
||||
NSDictionary *userInfo = [_launchOptions
|
||||
valueForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
|
||||
if ([userInfo count] >0) {
|
||||
NSError *error;
|
||||
@@ -261,7 +261,7 @@ static NSDictionary *_luanchOptions = nil;
|
||||
|
||||
#pragma mark- 内部方法
|
||||
+(void)setLaunchOptions:(NSDictionary *)theLaunchOptions{
|
||||
_luanchOptions = theLaunchOptions;
|
||||
_launchOptions = theLaunchOptions;
|
||||
|
||||
[JPUSHService setDebugMode];
|
||||
|
||||
@@ -289,7 +289,7 @@ static NSDictionary *_luanchOptions = nil;
|
||||
if(isIDFA){
|
||||
advertisingId = [[[ASIdentifierManager sharedManager] advertisingIdentifier] UUIDString];
|
||||
}
|
||||
[JPUSHService setupWithOption:_luanchOptions
|
||||
[JPUSHService setupWithOption:_launchOptions
|
||||
appKey:appkey
|
||||
channel:channel
|
||||
apsForProduction:[isProduction boolValue]
|
||||
|
||||
Reference in New Issue
Block a user