Skip to content

Commit 7007a16

Browse files
authored
Merge pull request #577 from JoshLipan/dev
Dev
2 parents 7a170d6 + d7e50c4 commit 7007a16

File tree

8 files changed

+109
-12
lines changed

8 files changed

+109
-12
lines changed
-136 KB
Binary file not shown.
147 KB
Binary file not shown.

android/src/main/java/cn/jpush/reactnativejpush/JPushModule.java

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import android.content.pm.ApplicationInfo;
1313
import android.os.Build;
1414
import android.os.Bundle;
15+
import android.util.Log;
1516
import android.util.SparseArray;
1617

1718
import com.facebook.react.bridge.Arguments;
@@ -108,7 +109,7 @@ public void onCatalystInstanceDestroy() {
108109

109110
@ReactMethod
110111
public void initPush() {
111-
mContext = getCurrentActivity();
112+
mContext = getReactApplicationContext();
112113
JPushInterface.init(getReactApplicationContext());
113114
Logger.toast(mContext, "Init push success");
114115
Logger.i(TAG, "init Success!");
@@ -133,7 +134,7 @@ public void getInfo(Callback successCallback) {
133134

134135
@ReactMethod
135136
public void stopPush() {
136-
mContext = getCurrentActivity();
137+
mContext = getReactApplicationContext();
137138
JPushInterface.stopPush(getReactApplicationContext());
138139
Logger.i(TAG, "Stop push");
139140
Logger.toast(mContext, "Stop push success");
@@ -148,7 +149,7 @@ public void hasPermission(Callback callback) {
148149

149150
@ReactMethod
150151
public void resumePush() {
151-
mContext = getCurrentActivity();
152+
mContext = getReactApplicationContext();
152153
JPushInterface.resumePush(getReactApplicationContext());
153154
Logger.i(TAG, "Resume push");
154155
Logger.toast(mContext, "Resume push success");
@@ -451,7 +452,7 @@ public void clearAllNotifications() {
451452
@ReactMethod
452453
public void clearNotificationById(int id) {
453454
try {
454-
mContext = getCurrentActivity();
455+
mContext = getReactApplicationContext();
455456
JPushInterface.clearNotificationById(mContext, id);
456457
} catch (Exception e) {
457458
e.printStackTrace();
@@ -461,7 +462,7 @@ public void clearNotificationById(int id) {
461462
@ReactMethod
462463
public void setLatestNotificationNumber(int number) {
463464
try {
464-
mContext = getCurrentActivity();
465+
mContext = getReactApplicationContext();
465466
JPushInterface.setLatestNotificationNumber(mContext, number);
466467
} catch (Exception e) {
467468
e.printStackTrace();
@@ -471,7 +472,7 @@ public void setLatestNotificationNumber(int number) {
471472
@ReactMethod
472473
public void setPushTime(ReadableMap map) {
473474
try {
474-
mContext = getCurrentActivity();
475+
mContext = getReactApplicationContext();
475476
ReadableArray array = map.getArray("days");
476477
Set<Integer> days = new HashSet<Integer>();
477478
for (int i=0; i < array.size(); i++) {
@@ -492,7 +493,7 @@ public void setPushTime(ReadableMap map) {
492493
@ReactMethod
493494
public void setSilenceTime(ReadableMap map) {
494495
try {
495-
mContext = getCurrentActivity();
496+
mContext = getReactApplicationContext();
496497
String starTime = map.getString("startTime");
497498
String endTime = map.getString("endTime");
498499
String[] sTime = starTime.split(":");
@@ -504,6 +505,28 @@ public void setSilenceTime(ReadableMap map) {
504505
}
505506
}
506507

508+
509+
@ReactMethod
510+
public void setGeofenceInterval(double interval) {
511+
try {
512+
mContext = getReactApplicationContext();
513+
JPushInterface.setGeofenceInterval(mContext, (long)interval);
514+
} catch (Exception e) {
515+
e.printStackTrace();
516+
}
517+
}
518+
519+
520+
@ReactMethod
521+
public void setMaxGeofenceNumber(int maxNumber) {
522+
try {
523+
mContext = getReactApplicationContext();
524+
JPushInterface.setMaxGeofenceNumber(mContext, maxNumber);
525+
} catch (Exception e) {
526+
e.printStackTrace();
527+
}
528+
}
529+
507530
@ReactMethod
508531
public void sendLocalNotification(ReadableMap map) {
509532
try {
@@ -778,7 +801,7 @@ public void finishActivity() {
778801

779802
private boolean hasPermission(String appOpsServiceId) {
780803

781-
Context context = getCurrentActivity().getApplicationContext();
804+
Context context = getReactApplicationContext();
782805
if (Build.VERSION.SDK_INT >= 24) {
783806
NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(
784807
Context.NOTIFICATION_SERVICE);

documents/api.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@
3737
* [setLatestNotificationNumber](#setlatestnotificationnumber)
3838
* [setSilenceTime](#setsilencetime)
3939
* [setPushTime](#setpushtime)
40+
* [setGeofenceInterval](#setgeofenceinterval)
41+
* [setMaxGeofenceNumber](#setmaxgeofencenumber)
4042
* [addGetRegistrationIdListener](#addgetregistrationIdlistener)
4143
* [removeGetRegistrationIdListener](#removegetregistrationidlistener)
4244

@@ -494,7 +496,32 @@ JPushModule.getLaunchAppNotification( notification => {
494496
JPushModule.setPushTime(config);
495497
```
496498

499+
* #### setGeofenceInterval
500+
501+
v2.5.0 开始支持,设置地理围栏监控周期,最小3分钟,最大1天。默认为15分钟,当距离地理围栏边界小于1000米周期自动调整为3分钟。设置成功后一直使用设置周期,不会进行调整。
502+
503+
504+
```
505+
/**
506+
* Android Only
507+
* @param interval number
508+
监控周期,单位是毫秒。
509+
*/
510+
JPushModule.setGeofenceInterval(interval);
511+
```
497512
513+
* #### setMaxGeofenceNumber
514+
515+
v2.5.0 开始支持,设置最多允许保存的地理围栏数量,超过最大限制后,如果继续创建先删除最早创建的地理围栏。默认数量为10个,允许设置最小1个,最大100个。
516+
517+
```
518+
/**
519+
* Android Only
520+
* @param maxNumber number
521+
最多允许保存的地理围栏个数
522+
*/
523+
JPushModule.setMaxGeofenceNumber(maxNumber);
524+
```
498525

499526
* #### addGetRegistrationIdListener (^2.1.4 Deprecated, 使用 [getRegistrationId](#getregistrationid) 代替)
500527

documents/api_en.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@
3737
* [setLatestNotificationNumber](#setlatestnotificationnumber)
3838
* [setSilenceTime](#setsilencetime)
3939
* [setPushTime](#setpushtime)
40+
* [setGeofenceInterval](#setgeofenceinterval)
41+
* [setMaxGeofenceNumber](#setmaxgeofencenumber)
4042
* [addGetRegistrationIdListener](#addgetregistrationidlistener)
4143
* [removeGetRegistrationIdListener](#removegetregistrationidlistener)
4244

@@ -458,7 +460,21 @@ JPushModule.getLaunchAppNotification( notification => {
458460
JPushModule.setPushTime(config);
459461
```
460462

463+
* #### setGeofenceInterval
464+
465+
Supported version: v2.5.0
466+
467+
```
468+
JPushModule.setGeofenceInterval(interval);
469+
```
461470
471+
* #### setMaxGeofenceNumber
472+
473+
Supported version: v2.5.0
474+
475+
```
476+
JPushModule.setMaxGeofenceNumber(maxNumber);
477+
```
462478

463479
* #### addGetRegistrationIdListener(^2.1.4 Deprecated, use [getRegistrationId](#getregistrationid) instead)
464480

index.d.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,15 @@ declare class JPush {
161161
*/
162162
static setPushTime(config: object): void
163163

164+
/**
165+
* Android Only
166+
*/
167+
static setGeofenceInterval(interval: number): void
168+
169+
/**
170+
* Android Only
171+
*/
172+
static setMaxGeofenceNumber(maxNumber: number): void
164173
/**
165174
* Android Only
166175
*/

index.js

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -273,15 +273,19 @@ export default class JPush {
273273
* Android Only
274274
*/
275275
static setLatestNotificationNumber (maxNumber) {
276-
JPushModule.setLatestNotificationNumber(maxNumber)
276+
if (Platform.OS == "android") {
277+
JPushModule.setLatestNotificationNumber(maxNumber)
278+
}
277279
}
278280

279281
/**
280282
* Android Only
281283
* @param {object} config = {"startTime": String, "endTime": String} // 例如:{startTime: "20:30", endTime: "8:30"}
282284
*/
283285
static setSilenceTime (config) {
284-
JPushModule.setSilenceTime(config)
286+
if (Platform.OS == "android") {
287+
JPushModule.setSilenceTime(config)
288+
}
285289
}
286290

287291
/**
@@ -290,7 +294,25 @@ export default class JPush {
290294
* // 例如:{days: [0, 6], startHour: 8, endHour: 23} 表示星期天和星期六的上午 8 点到晚上 11 点都可以推送
291295
*/
292296
static setPushTime (config) {
293-
JPushModule.setPushTime(config)
297+
if (Platform.OS == "android") {
298+
JPushModule.setPushTime(config)
299+
}
300+
}
301+
302+
/**
303+
* Android Only
304+
*/
305+
static setGeofenceInterval(interval) {
306+
if (Platform.OS == "android") {
307+
JPushModule.setGeofenceInterval(interval)
308+
}
309+
}
310+
311+
/**
312+
* Android Only
313+
*/
314+
static setMaxGeofenceNumber(maxNumber) {
315+
JPushModule.setMaxGeofenceNumber(maxNumber)
294316
}
295317

296318
/**

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "jpush-react-native",
3-
"version": "2.4.0",
3+
"version": "2.5.0",
44
"description": "a jpush plugin for react native application",
55
"main": "index.js",
66
"scripts": {

0 commit comments

Comments
 (0)