RNNotifications.m 1.81 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"
Lidan Hifi's avatar
Lidan Hifi committed
7

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

- (instancetype)init {
    self = [super init];
    _store = [RNNotificationsStore new];
    return self;
19
}
20

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

31
- (void)initialize {
yogevbd's avatar
WIP  
yogevbd committed
32
    _notificationEventHandler = [[RNNotificationEventHandler alloc] initWithStore:_store];
yogevbd's avatar
WIP  
yogevbd committed
33
    _notificationCenterListener = [[RNNotificationCenterListener alloc] initWithNotificationEventHandler:_notificationEventHandler];
Artal Druk's avatar
Artal Druk committed
34
}
35

yogevbd's avatar
WIP  
yogevbd committed
36
- (void)didRegisterForRemoteNotificationsWithDeviceToken:(id)deviceToken {
yogevbd's avatar
WIP  
yogevbd committed
37
    [_notificationEventHandler didRegisterForRemoteNotificationsWithDeviceToken:deviceToken];
38
}
Lidan Hifi's avatar
Lidan Hifi committed
39

yogevbd's avatar
WIP  
yogevbd committed
40
- (void)didFailToRegisterForRemoteNotificationsWithError:(NSError *)error {
yogevbd's avatar
WIP  
yogevbd committed
41
    [_notificationEventHandler didFailToRegisterForRemoteNotificationsWithError:error];
42
}
Lidan Hifi's avatar
Lidan Hifi committed
43

yogevbd's avatar
WIP  
yogevbd committed
44 45 46 47 48 49
- (void)setBadgeForNotification:(NSDictionary *)notification {
    if ([[notification objectForKey:@"aps"] objectForKey:@"badge"]){
        [[UIApplication sharedApplication] setApplicationIconBadgeNumber:[[[notification objectForKey:@"aps"] objectForKey:@"badge"] intValue]];
    }
}

yogevbd's avatar
WIP  
yogevbd committed
50 51 52 53 54 55 56 57
- (void)setInitialNotification:(NSDictionary *)notification {
    [_store setInitialNotification:notification];
}

- (void)finishHandleNotificationKey:(NSString *)notificationKey {
    [_store completeAction:notificationKey];
}

Lidan Hifi's avatar
Lidan Hifi committed
58
@end