Compare commits

...

24 Commits

Author SHA1 Message Date
Hevin 54f87adde2 Add API doc. 2016-07-12 14:09:48 +08:00
Hevin c101552938 Merge remote-tracking branch 'refs/remotes/origin/dev' 2016-07-12 13:54:29 +08:00
Hevin c918efb99a Update version number. 2016-07-12 13:53:12 +08:00
Hevin 9be760e65e Add API doc. 2016-07-12 13:47:19 +08:00
Hevin cea1eb85fa Add Android API. 2016-07-12 13:34:08 +08:00
E.B f8c56b5aa1 iOS - update API
1.更新检查用户通知设置 API 的参数
2016-07-12 11:52:47 +08:00
E.B 0bb6838477 iOS - update new API
1.添加检测用户通知设置的 API
2016-07-12 11:16:58 +08:00
Hevin c6b8a6f2f6 Update Plugin.xml. 2016-07-11 10:03:09 +08:00
Hevin 42fbe62d19 Merge branch 'dev' of https://github.com/jpush/jpush-phonegap-plugin into dev 2016-07-10 17:08:49 +08:00
Hevin d3ea41f513 Merge remote-tracking branch 'refs/remotes/origin/master' into dev 2016-07-10 17:05:53 +08:00
Hevin 5ff7d14bec Update Plugin name. 2016-07-10 17:05:05 +08:00
Hevin 1c41e96f42 Update README. 2016-07-08 13:26:39 +08:00
Hevin 48adf59ec8 Update README. 2016-07-07 17:54:48 +08:00
E.B 3369072687 iOS - update SDK 2.1.8
1.更新 iOS SDK 2.1.8
2016-07-01 10:34:49 +08:00
Hevin 8e7e957884 Merge remote-tracking branch 'refs/remotes/origin/dev' 2016-06-28 16:00:04 +08:00
Hevin c615f8255e Optimize installition & update Android SDK to 2.1.7 2016-06-28 15:57:34 +08:00
E.B 7ffec241fa iOS - fix #151
1. fix #151
2016-06-27 10:59:26 +08:00
Hevin de32f4a057 Format README 2016-06-27 10:40:03 +08:00
Hevin 1cd7ecf3e5 Merge remote-tracking branch 'refs/remotes/origin/dev' 2016-06-27 10:37:39 +08:00
Hevin b01b4bf259 Add dependency & Update README 2016-06-27 10:34:16 +08:00
Hevin f8efb4f010 Merge remote-tracking branch 'refs/remotes/origin/master' into dev 2016-06-27 10:29:39 +08:00
Hevin 870fc12c0d Merge remote-tracking branch 'refs/remotes/origin/dev' 2016-06-23 13:23:13 +08:00
Hevin dc2cdda00c Update README
Add QQ group badge.
2016-06-23 13:18:27 +08:00
Hevin 1c96487869 Update install script. 2016-06-17 17:44:42 +08:00
20 changed files with 146 additions and 123 deletions
+15 -26
View File
@@ -1,35 +1,29 @@
# JPush PhoneGap / Cordova Plugin
[![Build Status](https://travis-ci.org/jpush/jpush-phonegap-plugin.svg?branch=master)](https://travis-ci.org/jpush/jpush-phonegap-plugin)
[![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/jpush/jpush-phonegap-plugin)
[![release](https://img.shields.io/badge/release-2.1.5-blue.svg)](https://github.com/jpush/jpush-phonegap-plugin/releases)
[![QQ Group](https://img.shields.io/badge/QQ%20Group-413602425-red.svg)]()
[![release](https://img.shields.io/badge/release-2.2.1-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)
[![weibo](https://img.shields.io/badge/weibo-JPush-blue.svg)](http://weibo.com/jpush?refer_flag=1001030101_&is_all=1)
支持 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)。
> QQ 交流群:413602425
## 集成步骤
集成 JPush PhoneGap Plugin 有两种方法:
### 1.首先安装 cordova device 插件
cordova plugin add cordova-plugin-device
### 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 clone https://github.com/jpush/jpush-phonegap-plugin.git
@@ -40,12 +34,6 @@
- [iOS 手动安装文档地址](/doc/iOS_install.md)。
### 3.在 js 中调用函数,初始化 JPush
//由于 PhoneGap 插件采用了 lazy load 的特性,所以建议在 js 文件能执行的最开始就添加。
window.plugins.jPushPlugin.init();
## Demo
插件项目中包含一个简单的 Demo。若想参考,可以在 /example 文件夹内找到并拷贝以下文件:
@@ -77,7 +65,8 @@
## 常见问题
若要使用 CLI 来编译项目,注意应使用 cordova compile 而不是 cordova build 命令,因为 cordova build 会清除对插件文件的修改。
若要使用 CLI 来编译项目,注意应使用 cordova compile 而不是 cordova build 命令,因为如果修改了插件安装时默认写入到 AndroidManifest.xml
中的代码,cordova build 可能会导致对 AndroidManifest.xml 的修改。
Cordova CLI 的具体用法可参考 [Cordova CLI 官方文档](https://cordova.apache.org/docs/en/latest/reference/cordova-cli/index.html)。
### 1. Android
@@ -100,6 +89,6 @@ Eclipse 中 import PhoneGap 工程之后出现:*Type CallbackContext cannot be
## 更多
[JPush 官网文档](http://docs.jpush.io/)
如有问题可访问[极光社区](http://community.jpush.cn/)。
- QQ 群:413602425
- [JPush 官网文档](http://docs.jpush.io/)。
- 如有问题可访问[极光社区](http://community.jpush.cn/)。
+26 -1
View File
@@ -6,7 +6,7 @@
- [获取点击通知内容](#获取点击通知内容)
- [获取通知内容](#获取通知内容)
- [获取自定义消息推送内容](#获取自定义消息推送内容)
- [判断系统设置中是否允许当前应用推送](#判断系统设置中是否允许当前应用推送)
## 停止与恢复推送服务
### API - init
@@ -370,3 +370,28 @@ ps:点击通知后传递的 json object 保存在 window.plugins.jPushPlugin.r
"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) {
// 系统设置中打开了应用推送。
}
});
+5 -5
View File
@@ -57,7 +57,7 @@ JPush SDK 会恢复正常的默认行为。(因为保存在本地的状态数
### API - isPushStopped
iOS平台,检查推送服务是否注册
iOS平台,检查推送服务是否停止
#### 接口定义
@@ -69,12 +69,12 @@ iOS平台,检查推送服务是否注册。
- callback 回调函数,用来通知 JPush 的推送服务是否开启。
#### 代码示例
window.plugins.jPushPlugin.resumePush(callback)
var onCallback = function(data) {
window.plugins.jPushPlugin.isPushStopped(callback)
var callback = function(data) {
if(data > 0) {
// 开启
// 已关闭
} else {
// 关闭
// 已开启
}
}
BIN
View File
Binary file not shown.
+2 -2
View File
@@ -1,9 +1,9 @@
{
"name": "jpush-phonegap-plugin",
"version": "2.2.0",
"version": "2.2.2",
"description": "JPush for cordova plugin",
"cordova": {
"id": "cn.jpush.phonegap.JPushPlugin",
"id": "cordova-plugin-JPush",
"platforms": [
"ios",
"android"
+27 -18
View File
@@ -1,8 +1,8 @@
<?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.2.0">
id="cordova-plugin-JPush"
version="2.2.2">
<name>JPush Plugin</name>
<description>JPush for cordova plugin</description>
@@ -16,8 +16,10 @@
<engine name="cordova" version=">=3.0"/>
</engines>
<dependency id="org.apache.cordova.device" url="https://github.com/apache/cordova-plugin-device.git"/>
<js-module src="www/JPushPlugin.js" name="JPushPlugin">
<clobbers target="jPushPlugin"/>
<clobbers target="JPush"/>
</js-module>
<platform name="ios">
@@ -31,7 +33,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.7.a" framework="true" />
<source-file src="src/ios/lib/jpush-ios-2.1.8.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" />
@@ -51,19 +53,15 @@
</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"/>
</feature>
</config-file>
<framework src="com.android.support:support-v4:24.0.0" />
<config-file target="AndroidManifest.xml" parent="/manifest">
<!-- Required 一些系统要求的权限,如访问网络等-->
<uses-permission android:name="$PACKAGE_NAME.permission.JPUSH_MESSAGE"/>
@@ -139,10 +137,21 @@
<intent-filter>
<action android:name="android.intent.action.PACKAGE_ADDED"/>
<action android:name="android.intent.action.PACKAGE_REMOVED"/>
<data android:scheme="package"/>
</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"
@@ -174,15 +183,15 @@
<meta-data android:name="JPUSH_APPKEY" android:value="$API_KEY"/>
</config-file>
<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/jpush-android-2.1.7.jar" target-dir="libs"/>
<source-file src="src/android/armeabi/libjpush217.so" target-dir="libs/armeabi"/>
<source-file src="src/android/armeabi-v7a/libjpush217.so" target-dir="libs/armeabi-v7a"/>
<source-file src="src/android/arm64-v8a/libjpush217.so" target-dir="libs/arm64-v8a"/>
<source-file src="src/android/x86/libjpush217.so" target-dir="libs/x86"/>
<source-file src="src/android/x86_64/libjpush217.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"/>
<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"/>
-49
View File
@@ -1,49 +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-common/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);
});
}
};
+29 -14
View File
@@ -2,11 +2,10 @@ package cn.jpush.phonegap;
import android.app.Activity;
import android.content.Context;
import android.support.v4.app.NotificationManagerCompat;
import android.text.TextUtils;
import android.util.Log;
import __PACKAGE_NAME__.R;
import org.apache.cordova.CallbackContext;
import org.apache.cordova.CordovaInterface;
import org.apache.cordova.CordovaPlugin;
@@ -28,7 +27,6 @@ import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import cn.jpush.android.api.BasicPushNotificationBuilder;
import cn.jpush.android.api.CustomPushNotificationBuilder;
import cn.jpush.android.api.JPushInterface;
import cn.jpush.android.api.TagAliasCallback;
import cn.jpush.android.data.JPushLocalNotification;
@@ -37,6 +35,7 @@ public class JPushPlugin extends CordovaPlugin {
private final static List<String> methodList =
Arrays.asList(
"addLocalNotification",
"areNotificationEnabled",
"clearAllNotification",
"clearLocalNotifications",
"clearNotificationById",
@@ -314,6 +313,18 @@ public class JPushPlugin extends CordovaPlugin {
}
}
void areNotificationEnabled(JSONArray data, final CallbackContext callback) {
NotificationManagerCompat nmc = NotificationManagerCompat.from(
cordova.getActivity().getApplicationContext());
int isEnabled;
if (nmc.areNotificationsEnabled()) {
isEnabled = 1;
} else {
isEnabled = 0;
}
callback.success(isEnabled);
}
void setLatestNotificationNum(JSONArray data, CallbackContext callbackContext) {
int num = -1;
try {
@@ -438,19 +449,23 @@ public class JPushPlugin extends CordovaPlugin {
}
}
/**
* 自定义推送通知栏样式,需要自己实现具体代码。
* http://docs.jiguang.cn/client/android_tutorials/#_11
*/
void setCustomPushNotificationBuilder(JSONArray data,
CallbackContext callbackContext) {
CustomPushNotificationBuilder builder = new CustomPushNotificationBuilder(
this.cordova.getActivity(), R.layout.test_notification_layout,
R.id.icon, R.id.title, R.id.text);
builder.developerArg0 = "Custom Builder 1";
JPushInterface.setPushNotificationBuilder(2, builder);
JSONObject obj = new JSONObject();
try {
obj.put("id", 2);
} catch (JSONException e) {
e.printStackTrace();
}
// CustomPushNotificationBuilder builder = new CustomPushNotificationBuilder(
// this.cordova.getActivity(), R.layout.test_notification_layout,
// R.id.icon, R.id.title, R.id.text);
// builder.developerArg0 = "Custom Builder 1";
// JPushInterface.setPushNotificationBuilder(2, builder);
// JSONObject obj = new JSONObject();
// try {
// obj.put("id", 2);
// } catch (JSONException e) {
// e.printStackTrace();
// }
}
void clearAllNotification(JSONArray data, CallbackContext callbackContext) {
Binary file not shown.
Binary file not shown.
+3
View File
@@ -58,6 +58,9 @@
//地理位置上报 [latitude,longitude]
-(void)setLocation:(CDVInvokedUrlCommand*)command;
//检查用户的推送设置情况
-(void)getUserNotificationSettings:(CDVInvokedUrlCommand*)command;
/*
* 以下为js中可监听到的事件
* jpush.openNotification 点击推送消息启动或唤醒app
+18 -4
View File
@@ -52,7 +52,7 @@ static NSDictionary *_launchOptions = nil;
}else{
result = @(1);
}
[self hanleResultWithValue:result command:command];
[self handleResultWithValue:result command:command];
}
-(void)initial:(CDVInvokedUrlCommand*)command{
@@ -153,7 +153,7 @@ static NSDictionary *_launchOptions = nil;
-(void)getRegistrationID:(CDVInvokedUrlCommand*)command{
NSString* registrationID = [JPUSHService registrationID];
NSLog(@"### getRegistrationID %@",registrationID);
[self hanleResultWithValue:registrationID command:command];
[self handleResultWithValue:registrationID command:command];
}
-(void)startLogPageView:(CDVInvokedUrlCommand*)command{
@@ -222,7 +222,7 @@ static NSDictionary *_launchOptions = nil;
-(void)getApplicationIconBadgeNumber:(CDVInvokedUrlCommand *)command {
NSInteger num = [UIApplication sharedApplication].applicationIconBadgeNumber;
NSNumber *number = [NSNumber numberWithInteger:num];
[self hanleResultWithValue:number command:command];
[self handleResultWithValue:number command:command];
}
-(void)setDebugModeFromIos:(CDVInvokedUrlCommand*)command{
@@ -259,6 +259,20 @@ static NSDictionary *_launchOptions = nil;
[JPUSHService setLatitude:[((NSString*)command.arguments[0]) doubleValue] longitude:[((NSString*)command.arguments[1]) doubleValue]];
}
-(void)getUserNotificationSettings:(CDVInvokedUrlCommand*)command{
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;
@@ -298,7 +312,7 @@ static NSDictionary *_launchOptions = nil;
}
#pragma mark 将参数返回给js
-(void)hanleResultWithValue:(id)value command:(CDVInvokedUrlCommand*)command{
-(void)handleResultWithValue:(id)value command:(CDVInvokedUrlCommand*)command{
CDVPluginResult *result = nil;
CDVCommandStatus status = CDVCommandStatus_OK;
+1 -1
View File
@@ -9,7 +9,7 @@
* Copyright (c) 2011 ~ 2015 Shenzhen HXHG. All rights reserved.
*/
#define JPUSH_VERSION_NUMBER 2.1.7
#define JPUSH_VERSION_NUMBER 2.1.8
#import <Foundation/Foundation.h>
+17
View File
@@ -210,6 +210,23 @@ JPushPlugin.prototype.getApplicationIconBadgeNumber = function(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") {