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 | |
|---|---|---|---|
| 23ae6ad342 | |||
| ccfffc9a69 | |||
| 16c3c96844 | |||
| b2e818e88d | |||
| 5a8a926c50 | |||
| 0903b58270 | |||
| f0dc403ca8 | |||
| 5c53749171 | |||
| 68bb0ebfdf | |||
| 30fc85fc8d | |||
| fa0ca5f335 |
@@ -41,6 +41,27 @@
|
|||||||
```shell
|
```shell
|
||||||
cordova plugin add Your_Plugin_Path --variable APP_KEY=your_jpush_appkey
|
cordova plugin add Your_Plugin_Path --variable APP_KEY=your_jpush_appkey
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
### 参数
|
||||||
|
|
||||||
|
- APP_KEY: 必须设置,JPush 上注册的包名对应的 Appkey
|
||||||
|
|
||||||
|
```shell
|
||||||
|
--variable APP_KEY=your_jpush_appkey
|
||||||
|
```
|
||||||
|
|
||||||
|
- CHANNEL: 可以不设置,v3.6.0+ 版本开始支持(Android Only),方便开发者统计 APK 分发渠道,默认为 developer-default.
|
||||||
|
|
||||||
|
```shell
|
||||||
|
--variable CHANNEL=your_channel
|
||||||
|
```
|
||||||
|
|
||||||
|
- 同时动态配置 APP_KEY 和 CHANNEL 示例
|
||||||
|
|
||||||
|
```shell
|
||||||
|
cordova plugin add jpush-phonegap-plugin --variable APP_KEY=your_jpush_appkey --variable CHANNEL=your_channel
|
||||||
|
```
|
||||||
|
|
||||||
### Ionic
|
### Ionic
|
||||||
|
|
||||||
@@ -123,6 +144,10 @@ Android 的推送通过长连接的方式实现,只有在保持连接的情况
|
|||||||
|
|
||||||
### iOS
|
### iOS
|
||||||
|
|
||||||
|
#### XCode 10 收不到推送怎么办?
|
||||||
|
|
||||||
|
打开 xcode -> file -> WorkSpace Settings… -> Build System 改成 Legacy Build System 然后卸载 App 重新运行。
|
||||||
|
|
||||||
#### 打包时遇到 i386 打包失败怎么办?
|
#### 打包时遇到 i386 打包失败怎么办?
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
- [设置保留最近通知条数](#设置保留最近通知条数)
|
- [设置保留最近通知条数](#设置保留最近通知条数)
|
||||||
- [本地通知](#本地通知)
|
- [本地通知](#本地通知)
|
||||||
- [获取推送连接状态](#获取推送连接状态)
|
- [获取推送连接状态](#获取推送连接状态)
|
||||||
|
- [地理围栏](#地理围栏)
|
||||||
|
|
||||||
## 获取集成日志(同时适用于 iOS)
|
## 获取集成日志(同时适用于 iOS)
|
||||||
|
|
||||||
@@ -215,4 +215,34 @@ window.JPush.getConnectionState(function (result) {
|
|||||||
// 断开状态
|
// 断开状态
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## 地理围栏
|
||||||
|
|
||||||
|
### API - setGeofenceInterval
|
||||||
|
|
||||||
|
设置地理围栏监控周期,最小3分钟,最大1天。默认为15分钟,当距离地理围栏边界小于1000米周期自动调整为3分钟。设置成功后一直使用设置周期,不会进行调整。
|
||||||
|
|
||||||
|
#### 接口定义
|
||||||
|
|
||||||
|
```js
|
||||||
|
window.JPush.setGeofenceInterval(interval)
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 参数说明
|
||||||
|
|
||||||
|
- interval: 监控周期,单位是毫秒。
|
||||||
|
|
||||||
|
### API - setMaxGeofenceNumber
|
||||||
|
|
||||||
|
设置最多允许保存的地理围栏数量,超过最大限制后,如果继续创建先删除最早创建的地理围栏。默认数量为10个,允许设置最小1个,最大100个。
|
||||||
|
|
||||||
|
#### 接口定义
|
||||||
|
|
||||||
|
```js
|
||||||
|
window.JPush.setMaxGeofenceNumber(maxNumber)
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 参数说明
|
||||||
|
|
||||||
|
- maxNumber: 最多允许保存的地理围栏个数
|
||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "jpush-phonegap-plugin",
|
"name": "jpush-phonegap-plugin",
|
||||||
"version": "3.5.0",
|
"version": "3.6.1",
|
||||||
"description": "JPush for cordova plugin",
|
"description": "JPush for cordova plugin",
|
||||||
"cordova": {
|
"cordova": {
|
||||||
"id": "jpush-phonegap-plugin",
|
"id": "jpush-phonegap-plugin",
|
||||||
|
|||||||
+4
-3
@@ -2,7 +2,7 @@
|
|||||||
<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="jpush-phonegap-plugin"
|
id="jpush-phonegap-plugin"
|
||||||
version="3.5.0">
|
version="3.6.1">
|
||||||
|
|
||||||
<name>JPush</name>
|
<name>JPush</name>
|
||||||
<description>JPush for cordova plugin</description>
|
<description>JPush for cordova plugin</description>
|
||||||
@@ -11,6 +11,7 @@
|
|||||||
<license>MIT License</license>
|
<license>MIT License</license>
|
||||||
|
|
||||||
<preference name="APP_KEY" />
|
<preference name="APP_KEY" />
|
||||||
|
<preference name="CHANNEL" default="developer-default" />
|
||||||
|
|
||||||
<engines>
|
<engines>
|
||||||
<engine name="cordova" version=">=3.0" />
|
<engine name="cordova" version=">=3.0" />
|
||||||
@@ -212,11 +213,11 @@
|
|||||||
|
|
||||||
|
|
||||||
<!-- Required. Enable it you can get statistics data with channel -->
|
<!-- Required. Enable it you can get statistics data with channel -->
|
||||||
<meta-data android:name="JPUSH_CHANNEL" android:value="developer-default" />
|
<meta-data android:name="JPUSH_CHANNEL" android:value="$CHANNEL" />
|
||||||
<meta-data android:name="JPUSH_APPKEY" android:value="$APP_KEY" />
|
<meta-data android:name="JPUSH_APPKEY" android:value="$APP_KEY" />
|
||||||
</config-file>
|
</config-file>
|
||||||
|
|
||||||
<lib-file src="src/android/libs/jpush-android-3.1.7.jar" />
|
<lib-file src="src/android/libs/jpush-android-3.1.8.jar" />
|
||||||
|
|
||||||
<source-file src="src/android/JPushReceiver.java" target-dir="src/cn/jiguang/cordova/push" />
|
<source-file src="src/android/JPushReceiver.java" target-dir="src/cn/jiguang/cordova/push" />
|
||||||
<source-file src="src/android/JPushPlugin.java" target-dir="src/cn/jiguang/cordova/push" />
|
<source-file src="src/android/JPushPlugin.java" target-dir="src/cn/jiguang/cordova/push" />
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
package cn.jiguang.cordova.push;
|
package cn.jiguang.cordova.push;
|
||||||
|
|
||||||
import android.annotation.TargetApi;
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.app.AppOpsManager;
|
import android.app.AppOpsManager;
|
||||||
|
import android.app.NotificationManager;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.pm.ApplicationInfo;
|
import android.content.pm.ApplicationInfo;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
@@ -20,22 +20,17 @@ import org.json.JSONObject;
|
|||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.ExecutorService;
|
|
||||||
import java.util.concurrent.Executors;
|
|
||||||
|
|
||||||
import cn.jpush.android.api.BasicPushNotificationBuilder;
|
import cn.jpush.android.api.BasicPushNotificationBuilder;
|
||||||
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;
|
||||||
import cn.jpush.android.service.JPushMessageReceiver;
|
|
||||||
|
|
||||||
public class JPushPlugin extends CordovaPlugin {
|
public class JPushPlugin extends CordovaPlugin {
|
||||||
|
|
||||||
@@ -632,6 +627,16 @@ public class JPushPlugin extends CordovaPlugin {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void setGeofenceInterval(JSONArray data, CallbackContext callbackContext) throws JSONException {
|
||||||
|
long interval = data.getLong(0);
|
||||||
|
JPushInterface.setGeofenceInterval(this.cordova.getActivity(), interval);
|
||||||
|
}
|
||||||
|
|
||||||
|
void setMaxGeofenceNumber(JSONArray data, CallbackContext callbackContext) throws JSONException {
|
||||||
|
int maxNumber = data.getInt(0);
|
||||||
|
JPushInterface.setMaxGeofenceNumber(mContext, maxNumber);
|
||||||
|
}
|
||||||
|
|
||||||
private boolean isValidHour(int hour) {
|
private boolean isValidHour(int hour) {
|
||||||
return !(hour < 0 || hour > 23);
|
return !(hour < 0 || hour > 23);
|
||||||
}
|
}
|
||||||
@@ -673,35 +678,43 @@ public class JPushPlugin extends CordovaPlugin {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@TargetApi(Build.VERSION_CODES.KITKAT)
|
|
||||||
private boolean hasPermission(String appOpsServiceId) {
|
private boolean hasPermission(String appOpsServiceId) {
|
||||||
|
|
||||||
Context context = cordova.getActivity().getApplicationContext();
|
Context context = cordova.getActivity().getApplicationContext();
|
||||||
AppOpsManager mAppOps = (AppOpsManager) context.getSystemService(Context.APP_OPS_SERVICE);
|
if (Build.VERSION.SDK_INT >= 24) {
|
||||||
ApplicationInfo appInfo = context.getApplicationInfo();
|
NotificationManager mNotificationManager = (NotificationManager) context
|
||||||
|
.getSystemService(Context.NOTIFICATION_SERVICE);
|
||||||
|
return mNotificationManager.areNotificationsEnabled();
|
||||||
|
} else {
|
||||||
|
AppOpsManager mAppOps = (AppOpsManager) context.getSystemService(Context.APP_OPS_SERVICE);
|
||||||
|
ApplicationInfo appInfo = context.getApplicationInfo();
|
||||||
|
|
||||||
String pkg = context.getPackageName();
|
String pkg = context.getPackageName();
|
||||||
int uid = appInfo.uid;
|
int uid = appInfo.uid;
|
||||||
Class appOpsClazz;
|
Class appOpsClazz;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
appOpsClazz = Class.forName(AppOpsManager.class.getName());
|
appOpsClazz = Class.forName(AppOpsManager.class.getName());
|
||||||
Method checkOpNoThrowMethod = appOpsClazz.getMethod("checkOpNoThrow", Integer.TYPE, Integer.TYPE,
|
Method checkOpNoThrowMethod = appOpsClazz.getMethod("checkOpNoThrow", Integer.TYPE, Integer.TYPE,
|
||||||
String.class);
|
String.class);
|
||||||
Field opValue = appOpsClazz.getDeclaredField(appOpsServiceId);
|
Field opValue = appOpsClazz.getDeclaredField(appOpsServiceId);
|
||||||
int value = opValue.getInt(Integer.class);
|
int value = opValue.getInt(Integer.class);
|
||||||
Object result = checkOpNoThrowMethod.invoke(mAppOps, value, uid, pkg);
|
Object result = checkOpNoThrowMethod.invoke(mAppOps, value, uid, pkg);
|
||||||
return Integer.parseInt(result.toString()) == AppOpsManager.MODE_ALLOWED;
|
return Integer.parseInt(result.toString()) == AppOpsManager.MODE_ALLOWED;
|
||||||
} catch (InvocationTargetException e) {
|
} catch (InvocationTargetException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
} catch (IllegalAccessException e) {
|
} catch (IllegalAccessException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
} catch (NoSuchMethodException e) {
|
} catch (NoSuchMethodException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
} catch (NoSuchFieldException e) {
|
} catch (NoSuchFieldException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
} catch (ClassNotFoundException e) {
|
} catch (ClassNotFoundException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ import cn.jpush.android.api.JPushInterface;
|
|||||||
public class JPushReceiver extends BroadcastReceiver {
|
public class JPushReceiver extends BroadcastReceiver {
|
||||||
|
|
||||||
private static final List<String> IGNORED_EXTRAS_KEYS = Arrays.asList("cn.jpush.android.TITLE",
|
private static final List<String> IGNORED_EXTRAS_KEYS = Arrays.asList("cn.jpush.android.TITLE",
|
||||||
"cn.jpush.android.MESSAGE", "cn.jpush.android.APPKEY", "cn.jpush.android.NOTIFICATION_CONTENT_TITLE");
|
"cn.jpush.android.MESSAGE", "cn.jpush.android.APPKEY", "cn.jpush.android.NOTIFICATION_CONTENT_TITLE","key_show_entity","platform");
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onReceive(Context context, Intent intent) {
|
public void onReceive(Context context, Intent intent) {
|
||||||
|
|||||||
Binary file not shown.
Executable
BIN
Binary file not shown.
@@ -463,6 +463,18 @@ JPushPlugin.prototype.setPushTime = function(weekdays, startHour, endHour) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
JPushPlugin.prototype.setGeofenceInterval = function(interval) {
|
||||||
|
if (device.platform === "Android") {
|
||||||
|
this.callNative("setGeofenceInterval", [interval], null);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
JPushPlugin.prototype.setMaxGeofenceNumber = function(maxNumber) {
|
||||||
|
if (device.platform === "Android") {
|
||||||
|
this.callNative("setMaxGeofenceNumber", [maxNumber], null);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
if (!window.plugins) {
|
if (!window.plugins) {
|
||||||
window.plugins = {};
|
window.plugins = {};
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user