RNNotifications.m 2.05 KB
Newer Older
Lidan Hifi's avatar
Lidan Hifi committed
1 2

#import <UIKit/UIKit.h>
3
#import <PushKit/PushKit.h>
4 5
#import <React/RCTBridge.h>
#import "RNNotifications.h"
yogevbd's avatar
WIP  
yogevbd committed
6
#import "RNNotificationCenterListener.h"
yogevbd's avatar
WIP  
yogevbd committed
7
#import "RNPushKit.h"
Lidan Hifi's avatar
Lidan Hifi committed
8

9
@implementation RNNotifications {
yogevbd's avatar
WIP  
yogevbd committed
10
    RNPushKit* _pushKit;
yogevbd's avatar
WIP  
yogevbd committed
11
    RNNotificationCenterListener* _notificationCenterListener;
yogevbd's avatar
WIP  
yogevbd committed
12
    RNNotificationEventHandler* _notificationEventHandler;
yogevbd's avatar
WIP  
yogevbd committed
13
    RNPushKitEventHandler* _pushKitEventHandler;
yogevbd's avatar
WIP  
yogevbd committed
14 15 16 17 18
    RNEventEmitter* _eventEmitter;
}

- (instancetype)init {
    self = [super init];
19
    _notificationEventHandler = [[RNNotificationEventHandler alloc] initWithStore:[RNNotificationsStore new]];
yogevbd's avatar
WIP  
yogevbd committed
20
    return self;
21
}
22

yogevbd's avatar
WIP  
yogevbd committed
23 24 25 26 27 28 29 30 31 32
+ (instancetype)sharedInstance {
    static RNNotifications *sharedInstance = nil;
    static dispatch_once_t onceToken;
    
    dispatch_once(&onceToken, ^{
        sharedInstance = [[RNNotifications alloc] init];
    });
    return sharedInstance;
}

yogevbd's avatar
yogevbd committed
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
+ (void)startMonitorNotifications {
    [[self sharedInstance] startMonitorNotifications];
}

+ (void)startMonitorPushKitNotifications {
    [[self sharedInstance] startMonitorPushKitNotifications];
}

+ (void)didRegisterForRemoteNotificationsWithDeviceToken:(id)deviceToken {
    [[self sharedInstance] didRegisterForRemoteNotificationsWithDeviceToken:deviceToken];
}

+ (void)didFailToRegisterForRemoteNotificationsWithError:(NSError *)error {
    [[self sharedInstance] didFailToRegisterForRemoteNotificationsWithError:error];
}

- (void)startMonitorNotifications {
yogevbd's avatar
WIP  
yogevbd committed
50
    _notificationCenterListener = [[RNNotificationCenterListener alloc] initWithNotificationEventHandler:_notificationEventHandler];
Artal Druk's avatar
Artal Druk committed
51
}
52

yogevbd's avatar
yogevbd committed
53
- (void)startMonitorPushKitNotifications {
yogevbd's avatar
WIP  
yogevbd committed
54 55 56 57
    _pushKitEventHandler = [RNPushKitEventHandler new];
    _pushKit = [[RNPushKit alloc] initWithEventHandler:_pushKitEventHandler];
}

yogevbd's avatar
WIP  
yogevbd committed
58
- (void)didRegisterForRemoteNotificationsWithDeviceToken:(id)deviceToken {
yogevbd's avatar
WIP  
yogevbd committed
59
    [_notificationEventHandler didRegisterForRemoteNotificationsWithDeviceToken:deviceToken];
60
}
Lidan Hifi's avatar
Lidan Hifi committed
61

yogevbd's avatar
WIP  
yogevbd committed
62
- (void)didFailToRegisterForRemoteNotificationsWithError:(NSError *)error {
yogevbd's avatar
WIP  
yogevbd committed
63
    [_notificationEventHandler didFailToRegisterForRemoteNotificationsWithError:error];
64
}
Lidan Hifi's avatar
Lidan Hifi committed
65

Lidan Hifi's avatar
Lidan Hifi committed
66
@end