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

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

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

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

yogevbd's avatar
WIP  
yogevbd committed
22 23 24 25 26 27 28 29 30 31
+ (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
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
+ (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
49
    _notificationCenterListener = [[RNNotificationCenterListener alloc] initWithNotificationEventHandler:_notificationEventHandler];
Artal Druk's avatar
Artal Druk committed
50
}
51

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

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

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

Lidan Hifi's avatar
Lidan Hifi committed
65
@end