Skip to content

Commit

Permalink
Merge pull request #554 from jpush/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
JoshLipan authored Oct 23, 2018
2 parents e3d753d + 6befe18 commit d35f59a
Show file tree
Hide file tree
Showing 6 changed files with 108 additions and 7 deletions.
41 changes: 40 additions & 1 deletion android/src/main/java/cn/jpush/reactnativejpush/JPushModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

import com.facebook.react.bridge.Arguments;
import com.facebook.react.bridge.Callback;
import com.facebook.react.bridge.LifecycleEventListener;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;
Expand Down Expand Up @@ -39,7 +40,7 @@
import cn.jpush.android.data.JPushLocalNotification;
import cn.jpush.android.service.JPushMessageReceiver;

public class JPushModule extends ReactContextBaseJavaModule {
public class JPushModule extends ReactContextBaseJavaModule implements LifecycleEventListener {

private static String TAG = "JPushModule";
private Context mContext;
Expand All @@ -62,6 +63,7 @@ public class JPushModule extends ReactContextBaseJavaModule {

public JPushModule(ReactApplicationContext reactContext) {
super(reactContext);
reactContext.addLifecycleEventListener(this);
}

@Override
Expand All @@ -83,6 +85,7 @@ public void initialize() {
@Override
public void onCatalystInstanceDestroy() {
super.onCatalystInstanceDestroy();
Logger.i(TAG, "onCatalystInstanceDestroy");
mCachedBundle = null;
mRidBundle = null;
mConnectCachedBundle = null;
Expand All @@ -93,6 +96,7 @@ public void onCatalystInstanceDestroy() {
mRidEvent = null;
mConnectEvent = null;
mGetRidCallback = null;
mRAC = null;
}

@ReactMethod
Expand Down Expand Up @@ -511,6 +515,41 @@ public void sendLocalNotification(ReadableMap map) {
}
}

@ReactMethod
public void removeLocalNotification(int id) {
try {
Logger.d(TAG, "removeLocalNotification:"+id);
JPushInterface.removeLocalNotification(getReactApplicationContext(), id);
} catch (Exception e) {
e.printStackTrace();
}
}
@ReactMethod
public void clearLocalNotifications() {
try {
Logger.d(TAG, "clearLocalNotifications");
JPushInterface.clearLocalNotifications(getReactApplicationContext());
} catch (Exception e) {
e.printStackTrace();
}
}

@Override
public void onHostResume() {
Logger.d(TAG, "onHostResume");
}

@Override
public void onHostPause() {
Logger.d(TAG, "onHostPause");
}

@Override
public void onHostDestroy() {
Logger.d(TAG, "onHostDestroy");
mRAC = null;
}

/**
* 接收自定义消息,通知,通知点击事件等事件的广播
* 文档链接:http://docs.jiguang.cn/client/android_api/
Expand Down
21 changes: 20 additions & 1 deletion documents/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
* [setTags](#settags)
* [cleanTags](#cleantags)
* [sendLocalNotification](#sendlocalnotification)
* [clearLocalNotifications](#clearlocalnotifications)
* [removeLocalNotification](#removelocalnotification)
* [clearAllNotifications](#clearallnotifications)
* [clearNotificationById](#clearnotificationbyId)
* [点击推送事件](#点击推送事件)
Expand Down Expand Up @@ -194,6 +196,23 @@ JPushModule.resumePush();
})
```

#### clearLocalNotifications

移除所有的本地通知

```
JPushModule.clearLocalNotifications();
```

#### removeLocalNotification

根据 notificationId 移除指定的本地通知, notificationId 为 int 类型。

```
var notificationId = 5;
JPushModule.removeLocalNotification(notificationId);
```

#### clearAllNotifications

清除所有通知
Expand All @@ -208,7 +227,7 @@ JPushModule.clearAllNotifications();

```
var notificationId = 5;
JPushModule.clearNotificationById(id);
JPushModule.clearNotificationById(notificationId);
```

#### 点击推送事件
Expand Down
19 changes: 19 additions & 0 deletions documents/api_en.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
* [Receive Notification event](#receive-notification-event)
* [Receive Custom Message Event](#receive-custom-message-event)
* [sendLocalNotification](#sendlocalnotification)
* [removeLocalNotification](#removelocalnotification)
* [clearLocalNotifications](#clearlocalnotifications)
* [clearAllNotifications](#clearallnotifications)
* [clearNotificationById](#clearnotificationbyId)
* [iOS Only API](#ios-only-api)
Expand Down Expand Up @@ -149,6 +151,23 @@ reset tags.
})
```

#### clearLocalNotifications

Removes all local notifications

```
JPushModule.clearLocalNotifications();
```

#### removeLocalNotification

Remove the specified local notification by notificationId(int type)。

```
var notificationId = 5;
JPushModule.removeLocalNotification(id);
```

#### clearAllNotifications

Clear all notifications.
Expand Down
23 changes: 21 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,15 @@ export default class JPush {
}

/**
* Android Only
* Android Only.
* 删除通知栏指定的推送。
*/
static clearNotificationById (id) {
JPushModule.clearNotificationById(id)
if (Platform.OS == "android") {
JPushModule.clearNotificationById(id)
} else {
console.warn("iOS 没有提供该方法!")
}
}

/**
Expand Down Expand Up @@ -627,6 +632,20 @@ export default class JPush {
JPushModule.sendLocalNotification(notification)
}

/**
* 移除所有的本地通知
*/
static clearLocalNotifications() {
JPushModule.clearLocalNotifications()
}

/**
* 移除指定未触发的本地通知。
*/
static removeLocalNotification(id) {
JPushModule.removeLocalNotification(id)
}

/**
* iOS Only
* 设置应用 Badge(小红点)
Expand Down
7 changes: 6 additions & 1 deletion ios/RCTJPushModule/RCTJPushModule.m
Original file line number Diff line number Diff line change
Expand Up @@ -870,12 +870,17 @@ - (void)didRegistRemoteNotification:(NSString *)token {
}
}

RCT_EXPORT_METHOD(clearNotificationById:(NSInteger)identify) {
RCT_EXPORT_METHOD(removeLocalNotification:(NSInteger)identify) {
JPushNotificationIdentifier *pushIdentify = [[JPushNotificationIdentifier alloc] init];
pushIdentify.identifiers = @[[@(identify) description]];
[JPUSHService removeNotification: pushIdentify];
}

RCT_EXPORT_METHOD(clearLocalNotifications) {
[JPUSHService removeNotification: nil];
}


- (void)jpushNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(NSInteger))completionHandler {
NSDictionary * userInfo = notification.request.content.userInfo;
[JPUSHService handleRemoteNotification:userInfo];
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "jpush-react-native",
"version": "2.2.11",
"version": "2.2.12",
"description": "a jpush plugin for react native application",
"main": "index.js",
"scripts": {
Expand All @@ -24,7 +24,7 @@
},
"homepage": "https://github.com/jpush/jpush-react-native#readme",
"peerDependencies": {
"jcore-react-native": ">= 1.2.0"
"jcore-react-native": ">= 1.2.10"
},
"devDependencies": {
"babel-eslint": "^7.2.3",
Expand Down

0 comments on commit d35f59a

Please sign in to comment.