Skip to content

Commit 6befe18

Browse files
committed
iOS add removeLocalNotification clearLocalNotifications api
1 parent a7b8389 commit 6befe18

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed

index.js

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,15 @@ export default class JPush {
9999
}
100100

101101
/**
102-
* Android Only
102+
* Android Only.
103+
* 删除通知栏指定的推送。
103104
*/
104105
static clearNotificationById (id) {
105-
JPushModule.clearNotificationById(id)
106+
if (Platform.OS == "android") {
107+
JPushModule.clearNotificationById(id)
108+
} else {
109+
console.warn("iOS 没有提供该方法!")
110+
}
106111
}
107112

108113
/**
@@ -631,22 +636,14 @@ export default class JPush {
631636
* 移除所有的本地通知
632637
*/
633638
static clearLocalNotifications() {
634-
if (Platform.OS == "android") {
635639
JPushModule.clearLocalNotifications()
636-
} else {
637-
638-
}
639640
}
640641

641642
/**
642-
* 移除指定的本地通知
643+
* 移除指定未触发的本地通知。
643644
*/
644645
static removeLocalNotification(id) {
645-
if (Platform.OS == "android") {
646646
JPushModule.removeLocalNotification(id)
647-
} else {
648-
649-
}
650647
}
651648

652649
/**

ios/RCTJPushModule/RCTJPushModule.m

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -870,12 +870,17 @@ - (void)didRegistRemoteNotification:(NSString *)token {
870870
}
871871
}
872872

873-
RCT_EXPORT_METHOD(clearNotificationById:(NSInteger)identify) {
873+
RCT_EXPORT_METHOD(removeLocalNotification:(NSInteger)identify) {
874874
JPushNotificationIdentifier *pushIdentify = [[JPushNotificationIdentifier alloc] init];
875875
pushIdentify.identifiers = @[[@(identify) description]];
876876
[JPUSHService removeNotification: pushIdentify];
877877
}
878878

879+
RCT_EXPORT_METHOD(clearLocalNotifications) {
880+
[JPUSHService removeNotification: nil];
881+
}
882+
883+
879884
- (void)jpushNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(NSInteger))completionHandler {
880885
NSDictionary * userInfo = notification.request.content.userInfo;
881886
[JPUSHService handleRemoteNotification:userInfo];

0 commit comments

Comments
 (0)