-
Notifications
You must be signed in to change notification settings - Fork 767
/
Copy pathRNCommandsHandler.m
93 lines (72 loc) · 3.26 KB
/
RNCommandsHandler.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#import "RNCommandsHandler.h"
#import "RNNotifications.h"
#import "RNNotificationsStore.h"
#import "RCTConvert+RNNotifications.h"
@implementation RNCommandsHandler {
RNNotificationCenter* _notificationCenter;
}
- (instancetype)init {
self = [super init];
_notificationCenter = [RNNotificationCenter new];
return self;
}
- (void)requestPermissions:(NSDictionary *)options {
[_notificationCenter requestPermissions:options];
}
- (void)setCategories:(NSArray *)categories {
[_notificationCenter setCategories:categories];
}
- (void)getInitialNotification:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject {
NSDictionary* initialNotification = [[RNNotificationsStore sharedInstance] initialNotification];
[[RNNotificationsStore sharedInstance] setInitialNotification:nil];
resolve(initialNotification);
}
- (void)finishHandlingAction:(NSString *)completionKey {
[[RNNotificationsStore sharedInstance] completeAction:completionKey];
}
- (void)finishPresentingNotification:(NSString *)completionKey presentingOptions:(NSDictionary *)presentingOptions {
[[RNNotificationsStore sharedInstance] completePresentation:completionKey withPresentationOptions:[RCTConvert UNNotificationPresentationOptions:presentingOptions]];
}
- (void)finishHandlingBackgroundAction:(NSString *)completionKey backgroundFetchResult:(NSString *)backgroundFetchResult {
[[RNNotificationsStore sharedInstance] completeBackgroundAction:completionKey withBackgroundFetchResult:[RCTConvert UIBackgroundFetchResult:backgroundFetchResult]];
}
- (void)abandonPermissions {
[[UIApplication sharedApplication] unregisterForRemoteNotifications];
}
- (void)registerPushKit {
[RNNotifications startMonitorPushKitNotifications];
}
- (void)getBadgeCount:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject {
NSInteger count = [UIApplication sharedApplication].applicationIconBadgeNumber;
resolve([NSNumber numberWithInteger:count]);
}
- (void)setBadgeCount:(int)count {
dispatch_async(dispatch_get_main_queue(), ^{
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:count];
});
}
- (void)postLocalNotification:(NSDictionary *)notification withId:(NSNumber *)notificationId {
[_notificationCenter postLocalNotification:notification withId:notificationId];
}
- (void)cancelLocalNotification:(NSNumber *)notificationId {
[_notificationCenter cancelLocalNotification:notificationId];
}
- (void)cancelAllLocalNotifications {
[_notificationCenter cancelAllLocalNotifications];
}
- (void)isRegisteredForRemoteNotifications:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject {
[_notificationCenter isRegisteredForRemoteNotifications:resolve];
}
- (void)checkPermissions:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject {
[_notificationCenter checkPermissions:resolve];
}
- (void)removeAllDeliveredNotifications {
[_notificationCenter removeAllDeliveredNotifications];
}
- (void)removeDeliveredNotifications:(NSArray<NSString *> *)identifiers {
[_notificationCenter removeDeliveredNotifications:identifiers];
}
- (void)getDeliveredNotifications:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject {
[_notificationCenter getDeliveredNotifications:resolve];
}
@end