mirror of
https://github.com/jpush/jpush-phonegap-plugin.git
synced 2026-04-19 00:03:45 +08:00
Compare commits
14 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 54f87adde2 | |||
| c101552938 | |||
| c918efb99a | |||
| 9be760e65e | |||
| cea1eb85fa | |||
| f8c56b5aa1 | |||
| 0bb6838477 | |||
| c6b8a6f2f6 | |||
| 42fbe62d19 | |||
| d3ea41f513 | |||
| 5ff7d14bec | |||
| 1c41e96f42 | |||
| 48adf59ec8 | |||
| 3369072687 |
@@ -7,7 +7,9 @@
|
|||||||
[](http://weibo.com/jpush?refer_flag=1001030101_&is_all=1)
|
[](http://weibo.com/jpush?refer_flag=1001030101_&is_all=1)
|
||||||
|
|
||||||
支持 iOS, Android 的 Cordova 推送插件。
|
支持 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 有两种方法:
|
集成 JPush PhoneGap Plugin 有两种方法:
|
||||||
@@ -87,6 +89,6 @@ Eclipse 中 import PhoneGap 工程之后出现:*Type CallbackContext cannot be
|
|||||||
|
|
||||||
|
|
||||||
## 更多
|
## 更多
|
||||||
[JPush 官网文档](http://docs.jpush.io/)。
|
- QQ 群:413602425。
|
||||||
|
- [JPush 官网文档](http://docs.jpush.io/)。
|
||||||
如有问题可访问[极光社区](http://community.jpush.cn/)。
|
- 如有问题可访问[极光社区](http://community.jpush.cn/)。
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
- [获取点击通知内容](#获取点击通知内容)
|
- [获取点击通知内容](#获取点击通知内容)
|
||||||
- [获取通知内容](#获取通知内容)
|
- [获取通知内容](#获取通知内容)
|
||||||
- [获取自定义消息推送内容](#获取自定义消息推送内容)
|
- [获取自定义消息推送内容](#获取自定义消息推送内容)
|
||||||
|
- [判断系统设置中是否允许当前应用推送](#判断系统设置中是否允许当前应用推送)
|
||||||
|
|
||||||
## 停止与恢复推送服务
|
## 停止与恢复推送服务
|
||||||
### API - init
|
### API - init
|
||||||
@@ -370,3 +370,28 @@ ps:点击通知后传递的 json object 保存在 window.plugins.jPushPlugin.r
|
|||||||
"content":"今天去哪儿",
|
"content":"今天去哪儿",
|
||||||
"extras":{"key":"不填写没有"}
|
"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) {
|
||||||
|
// 系统设置中打开了应用推送。
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|||||||
Vendored
BIN
Binary file not shown.
+2
-2
@@ -1,9 +1,9 @@
|
|||||||
{
|
{
|
||||||
"name": "jpush-phonegap-plugin",
|
"name": "jpush-phonegap-plugin",
|
||||||
"version": "2.2.1",
|
"version": "2.2.2",
|
||||||
"description": "JPush for cordova plugin",
|
"description": "JPush for cordova plugin",
|
||||||
"cordova": {
|
"cordova": {
|
||||||
"id": "cn.jpush.phonegap.JPushPlugin",
|
"id": "cordova-plugin-JPush",
|
||||||
"platforms": [
|
"platforms": [
|
||||||
"ios",
|
"ios",
|
||||||
"android"
|
"android"
|
||||||
|
|||||||
+19
-7
@@ -1,8 +1,8 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
|
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
id="cn.jpush.phonegap.JPushPlugin"
|
id="cordova-plugin-JPush"
|
||||||
version="2.2.1">
|
version="2.2.2">
|
||||||
|
|
||||||
<name>JPush Plugin</name>
|
<name>JPush Plugin</name>
|
||||||
<description>JPush for cordova plugin</description>
|
<description>JPush for cordova plugin</description>
|
||||||
@@ -16,10 +16,10 @@
|
|||||||
<engine name="cordova" version=">=3.0"/>
|
<engine name="cordova" version=">=3.0"/>
|
||||||
</engines>
|
</engines>
|
||||||
|
|
||||||
<dependency id="org.apache.cordova.device" url="https://github.com/apache/cordova-plugin-device.git" />
|
<dependency id="org.apache.cordova.device" url="https://github.com/apache/cordova-plugin-device.git"/>
|
||||||
|
|
||||||
<js-module src="www/JPushPlugin.js" name="JPushPlugin">
|
<js-module src="www/JPushPlugin.js" name="JPushPlugin">
|
||||||
<clobbers target="jPushPlugin"/>
|
<clobbers target="JPush"/>
|
||||||
</js-module>
|
</js-module>
|
||||||
|
|
||||||
<platform name="ios">
|
<platform name="ios">
|
||||||
@@ -33,7 +33,7 @@
|
|||||||
<source-file src="src/ios/Plugins/JPushPlugin.m"/>
|
<source-file src="src/ios/Plugins/JPushPlugin.m"/>
|
||||||
|
|
||||||
<header-file src="src/ios/lib/JPUSHService.h" />
|
<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"/>
|
<header-file src="src/ios/Plugins/AppDelegate+JPush.h"/>
|
||||||
<source-file src="src/ios/Plugins/AppDelegate+JPush.m"/>
|
<source-file src="src/ios/Plugins/AppDelegate+JPush.m"/>
|
||||||
<resource-file src="src/ios/PushConfig.plist" />
|
<resource-file src="src/ios/PushConfig.plist" />
|
||||||
@@ -53,7 +53,6 @@
|
|||||||
</config-file>
|
</config-file>
|
||||||
</platform>
|
</platform>
|
||||||
|
|
||||||
<!-- android -->
|
|
||||||
<platform name="android">
|
<platform name="android">
|
||||||
<config-file target="res/xml/config.xml" parent="/*">
|
<config-file target="res/xml/config.xml" parent="/*">
|
||||||
<feature name="JPushPlugin">
|
<feature name="JPushPlugin">
|
||||||
@@ -61,6 +60,8 @@
|
|||||||
</feature>
|
</feature>
|
||||||
</config-file>
|
</config-file>
|
||||||
|
|
||||||
|
<framework src="com.android.support:support-v4:24.0.0" />
|
||||||
|
|
||||||
<config-file target="AndroidManifest.xml" parent="/manifest">
|
<config-file target="AndroidManifest.xml" parent="/manifest">
|
||||||
<!-- Required 一些系统要求的权限,如访问网络等-->
|
<!-- Required 一些系统要求的权限,如访问网络等-->
|
||||||
<uses-permission android:name="$PACKAGE_NAME.permission.JPUSH_MESSAGE"/>
|
<uses-permission android:name="$PACKAGE_NAME.permission.JPUSH_MESSAGE"/>
|
||||||
@@ -139,6 +140,18 @@
|
|||||||
</intent-filter>
|
</intent-filter>
|
||||||
</receiver>
|
</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 用户自定义的广播接收器 -->
|
<!-- User defined. For test only 用户自定义的广播接收器 -->
|
||||||
<receiver
|
<receiver
|
||||||
android:name="cn.jpush.phonegap.MyReceiver"
|
android:name="cn.jpush.phonegap.MyReceiver"
|
||||||
@@ -177,7 +190,6 @@
|
|||||||
<source-file src="src/android/x86/libjpush217.so" target-dir="libs/x86"/>
|
<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/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/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/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/test_notification_layout.xml" target-dir="res/layout"/>
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package cn.jpush.phonegap;
|
|||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.support.v4.app.NotificationManagerCompat;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
@@ -26,7 +27,6 @@ import java.util.concurrent.ExecutorService;
|
|||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
|
|
||||||
import cn.jpush.android.api.BasicPushNotificationBuilder;
|
import cn.jpush.android.api.BasicPushNotificationBuilder;
|
||||||
import cn.jpush.android.api.CustomPushNotificationBuilder;
|
|
||||||
import cn.jpush.android.api.JPushInterface;
|
import cn.jpush.android.api.JPushInterface;
|
||||||
import cn.jpush.android.api.TagAliasCallback;
|
import cn.jpush.android.api.TagAliasCallback;
|
||||||
import cn.jpush.android.data.JPushLocalNotification;
|
import cn.jpush.android.data.JPushLocalNotification;
|
||||||
@@ -35,6 +35,7 @@ public class JPushPlugin extends CordovaPlugin {
|
|||||||
private final static List<String> methodList =
|
private final static List<String> methodList =
|
||||||
Arrays.asList(
|
Arrays.asList(
|
||||||
"addLocalNotification",
|
"addLocalNotification",
|
||||||
|
"areNotificationEnabled",
|
||||||
"clearAllNotification",
|
"clearAllNotification",
|
||||||
"clearLocalNotifications",
|
"clearLocalNotifications",
|
||||||
"clearNotificationById",
|
"clearNotificationById",
|
||||||
@@ -312,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) {
|
void setLatestNotificationNum(JSONArray data, CallbackContext callbackContext) {
|
||||||
int num = -1;
|
int num = -1;
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -58,6 +58,9 @@
|
|||||||
//地理位置上报 [latitude,longitude]
|
//地理位置上报 [latitude,longitude]
|
||||||
-(void)setLocation:(CDVInvokedUrlCommand*)command;
|
-(void)setLocation:(CDVInvokedUrlCommand*)command;
|
||||||
|
|
||||||
|
//检查用户的推送设置情况
|
||||||
|
-(void)getUserNotificationSettings:(CDVInvokedUrlCommand*)command;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* 以下为js中可监听到的事件
|
* 以下为js中可监听到的事件
|
||||||
* jpush.openNotification 点击推送消息启动或唤醒app
|
* jpush.openNotification 点击推送消息启动或唤醒app
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ static NSDictionary *_launchOptions = nil;
|
|||||||
}else{
|
}else{
|
||||||
result = @(1);
|
result = @(1);
|
||||||
}
|
}
|
||||||
[self hanleResultWithValue:result command:command];
|
[self handleResultWithValue:result command:command];
|
||||||
}
|
}
|
||||||
|
|
||||||
-(void)initial:(CDVInvokedUrlCommand*)command{
|
-(void)initial:(CDVInvokedUrlCommand*)command{
|
||||||
@@ -153,7 +153,7 @@ static NSDictionary *_launchOptions = nil;
|
|||||||
-(void)getRegistrationID:(CDVInvokedUrlCommand*)command{
|
-(void)getRegistrationID:(CDVInvokedUrlCommand*)command{
|
||||||
NSString* registrationID = [JPUSHService registrationID];
|
NSString* registrationID = [JPUSHService registrationID];
|
||||||
NSLog(@"### getRegistrationID %@",registrationID);
|
NSLog(@"### getRegistrationID %@",registrationID);
|
||||||
[self hanleResultWithValue:registrationID command:command];
|
[self handleResultWithValue:registrationID command:command];
|
||||||
}
|
}
|
||||||
|
|
||||||
-(void)startLogPageView:(CDVInvokedUrlCommand*)command{
|
-(void)startLogPageView:(CDVInvokedUrlCommand*)command{
|
||||||
@@ -222,7 +222,7 @@ static NSDictionary *_launchOptions = nil;
|
|||||||
-(void)getApplicationIconBadgeNumber:(CDVInvokedUrlCommand *)command {
|
-(void)getApplicationIconBadgeNumber:(CDVInvokedUrlCommand *)command {
|
||||||
NSInteger num = [UIApplication sharedApplication].applicationIconBadgeNumber;
|
NSInteger num = [UIApplication sharedApplication].applicationIconBadgeNumber;
|
||||||
NSNumber *number = [NSNumber numberWithInteger:num];
|
NSNumber *number = [NSNumber numberWithInteger:num];
|
||||||
[self hanleResultWithValue:number command:command];
|
[self handleResultWithValue:number command:command];
|
||||||
}
|
}
|
||||||
|
|
||||||
-(void)setDebugModeFromIos:(CDVInvokedUrlCommand*)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]];
|
[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- 内部方法
|
#pragma mark- 内部方法
|
||||||
+(void)setLaunchOptions:(NSDictionary *)theLaunchOptions{
|
+(void)setLaunchOptions:(NSDictionary *)theLaunchOptions{
|
||||||
_launchOptions = theLaunchOptions;
|
_launchOptions = theLaunchOptions;
|
||||||
@@ -298,7 +312,7 @@ static NSDictionary *_launchOptions = nil;
|
|||||||
}
|
}
|
||||||
|
|
||||||
#pragma mark 将参数返回给js
|
#pragma mark 将参数返回给js
|
||||||
-(void)hanleResultWithValue:(id)value command:(CDVInvokedUrlCommand*)command{
|
-(void)handleResultWithValue:(id)value command:(CDVInvokedUrlCommand*)command{
|
||||||
CDVPluginResult *result = nil;
|
CDVPluginResult *result = nil;
|
||||||
CDVCommandStatus status = CDVCommandStatus_OK;
|
CDVCommandStatus status = CDVCommandStatus_OK;
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
* Copyright (c) 2011 ~ 2015 Shenzhen HXHG. All rights reserved.
|
* 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>
|
#import <Foundation/Foundation.h>
|
||||||
|
|
||||||
|
|||||||
Binary file not shown.
@@ -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
|
// Android methods
|
||||||
JPushPlugin.prototype.setDebugMode = function(mode) {
|
JPushPlugin.prototype.setDebugMode = function(mode) {
|
||||||
if(device.platform == "Android") {
|
if(device.platform == "Android") {
|
||||||
|
|||||||
Reference in New Issue
Block a user