Skip to content

Commit 3c5a238

Browse files
committed
add stopPush in iOS
1 parent 1b95d6b commit 3c5a238

File tree

4 files changed

+24
-5
lines changed

4 files changed

+24
-5
lines changed

example/documents/APIs.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,9 +334,10 @@ setLocalNotification( Date, // date local notification fire data
334334

335335
- #### clearNotificationById
336336

337-
Clear notification by id.
337+
Clear notification by id(int type).
338338

339339
```
340+
var id = 5;
340341
JPushModule.clearNotificationById(id);
341342
```
342343

example/documents/APIs_zh.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -381,9 +381,10 @@ setLocalNotification( Date, // date 触发本地推送的时间
381381

382382
- #### clearNotificationById
383383

384-
根据 notificationId 来清除通知
384+
根据 notificationId 来清除通知, notificationId 为 int 类型。
385385

386386
```
387+
var notificationId = 5;
387388
JPushModule.clearNotificationById(id);
388389
```
389390

index.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,6 @@ export default class JPush {
5353
JPushModule.initPush();
5454
}
5555

56-
/**
57-
* Android Only
58-
*/
5956
static stopPush() {
6057
JPushModule.stopPush();
6158
}
@@ -525,6 +522,8 @@ export default class JPush {
525522
JPushModule.setupPush();
526523
}
527524

525+
526+
528527
/**
529528
* iOS Only
530529
* @param {Function} cb = (String) => { } // 返回 appKey

ios/RCTJPushModule/RCTJPushModule.m

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,10 @@ - (void)setBridge:(RCTBridge *)bridge {
141141
[JPUSHService registerForRemoteNotificationConfig:entity delegate:self];
142142
}
143143

144+
RCT_EXPORT_METHOD(stopPush) {
145+
[[UIApplication sharedApplication] unregisterForRemoteNotifications];
146+
}
147+
144148
RCT_EXPORT_METHOD(getApplicationIconBadge:(RCTResponseSenderBlock)callback) {
145149
callback(@[@([UIApplication sharedApplication].applicationIconBadgeNumber)]);
146150
}
@@ -739,6 +743,20 @@ - (void)didRegistRemoteNotification:(NSString *)token {
739743
[JPUSHService setLogOFF];
740744
}
741745

746+
RCT_EXPORT_METHOD(clearAllNotifications) {
747+
if ([[UIDevice currentDevice].systemVersion floatValue] >= 10.0) {
748+
[UNUserNotificationCenter.currentNotificationCenter removeAllPendingNotificationRequests];
749+
} else {
750+
[[UIApplication sharedApplication] cancelAllLocalNotifications];
751+
}
752+
}
753+
754+
RCT_EXPORT_METHOD(clearNotificationById:(NSInteger)identify) {
755+
JPushNotificationIdentifier *pushIdentify = [[JPushNotificationIdentifier alloc] init];
756+
pushIdentify.identifiers = @[[@(identify) description]];
757+
[JPUSHService removeNotification: pushIdentify];
758+
}
759+
742760
- (void)jpushNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(NSInteger))completionHandler {
743761
NSDictionary * userInfo = notification.request.content.userInfo;
744762
[JPUSHService handleRemoteNotification:userInfo];

0 commit comments

Comments
 (0)