-
Notifications
You must be signed in to change notification settings - Fork 767
/
Copy pathRNNotifications.m
102 lines (79 loc) · 3.63 KB
/
RNNotifications.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
94
95
96
97
98
99
100
101
102
#import <UIKit/UIKit.h>
#import <PushKit/PushKit.h>
#import "RNNotifications.h"
#import "RNNotificationCenterListener.h"
#import "RNPushKit.h"
#import "RNNotificationCenterMulticast.h"
@implementation RNNotifications {
RNPushKit* _pushKit;
RNNotificationCenterListener* _notificationCenterListener;
RNNotificationEventHandler* _notificationEventHandler;
RNNotificationsStore* _store;
RNPushKitEventHandler* _pushKitEventHandler;
RNEventEmitter* _eventEmitter;
RNNotificationCenterMulticast* _notificationCenterMulticast;
}
- (instancetype)init {
self = [super init];
_store = [RNNotificationsStore sharedInstance];
_notificationEventHandler = [[RNNotificationEventHandler alloc] initWithStore:_store];
return self;
}
+ (instancetype)sharedInstance {
static RNNotifications *sharedInstance = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
sharedInstance = [[RNNotifications alloc] init];
});
return sharedInstance;
}
+ (void)startMonitorNotifications {
[[self sharedInstance] startMonitorNotifications];
}
+ (void)startMonitorPushKitNotifications {
[[self sharedInstance] startMonitorPushKitNotifications];
}
+ (void)didReceiveBackgroundNotification:(NSDictionary *)userInfo withCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
[[self sharedInstance] didReceiveBackgroundNotification:userInfo withCompletionHandler:completionHandler];
}
+ (void)didRegisterForRemoteNotificationsWithDeviceToken:(id)deviceToken {
[[self sharedInstance] didRegisterForRemoteNotificationsWithDeviceToken:deviceToken];
}
+ (void)didFailToRegisterForRemoteNotificationsWithError:(NSError *)error {
[[self sharedInstance] didFailToRegisterForRemoteNotificationsWithError:error];
}
+ (void)addNativeDelegate:(id<UNUserNotificationCenterDelegate>)delegate {
[[self sharedInstance] addNativeDelegate:delegate];
}
+ (void)removeNativeDelegate:(id<UNUserNotificationCenterDelegate>)delegate {
[[self sharedInstance] removeNativeDelegate:delegate];
}
- (RNNotificationCenterMulticast*)multicast {
return _notificationCenterMulticast;
}
- (void)startMonitorNotifications {
_notificationCenterListener = [[RNNotificationCenterListener alloc] initWithNotificationEventHandler:_notificationEventHandler];
_notificationCenterMulticast = [[RNNotificationCenterMulticast alloc] init];
[[UNUserNotificationCenter currentNotificationCenter] setDelegate:_notificationCenterMulticast];
[_notificationCenterMulticast addNativeDelegate:_notificationCenterListener];
}
- (void)startMonitorPushKitNotifications {
_pushKitEventHandler = [[RNPushKitEventHandler alloc] initWithStore:_store];
_pushKit = [[RNPushKit alloc] initWithEventHandler:_pushKitEventHandler];
}
- (void)didReceiveBackgroundNotification:(NSDictionary *)userInfo withCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
[_notificationEventHandler didReceiveBackgroundNotification:userInfo withCompletionHandler:completionHandler];
}
- (void)didRegisterForRemoteNotificationsWithDeviceToken:(id)deviceToken {
[_notificationEventHandler didRegisterForRemoteNotificationsWithDeviceToken:deviceToken];
}
- (void)didFailToRegisterForRemoteNotificationsWithError:(NSError *)error {
[_notificationEventHandler didFailToRegisterForRemoteNotificationsWithError:error];
}
- (void)addNativeDelegate:(id<UNUserNotificationCenterDelegate>)delegate {
[_notificationCenterMulticast addNativeDelegate:delegate];
}
- (void)removeNativeDelegate:(id<UNUserNotificationCenterDelegate>)delegate {
[_notificationCenterMulticast removeNativeDelegate:delegate];
}
@end