RNNotifications.m 1.38 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;
11
}
12

yogevbd's avatar
WIP  
yogevbd committed
13 14 15 16 17 18 19 20 21 22
+ (instancetype)sharedInstance {
    static RNNotifications *sharedInstance = nil;
    static dispatch_once_t onceToken;
    
    dispatch_once(&onceToken, ^{
        sharedInstance = [[RNNotifications alloc] init];
    });
    return sharedInstance;
}

23
- (void)initialize {
yogevbd's avatar
WIP  
yogevbd committed
24 25
    _notificationEventHandler = [RNNotificationEventHandler new];
    _notificationCenterListener = [[RNNotificationCenterListener alloc] initWithNotificationEventHandler:_notificationEventHandler];
Artal Druk's avatar
Artal Druk committed
26
}
27

yogevbd's avatar
WIP  
yogevbd committed
28
- (void)didRegisterForRemoteNotificationsWithDeviceToken:(id)deviceToken {
yogevbd's avatar
WIP  
yogevbd committed
29
    [_notificationEventHandler didRegisterForRemoteNotificationsWithDeviceToken:deviceToken];
30
}
Lidan Hifi's avatar
Lidan Hifi committed
31

yogevbd's avatar
WIP  
yogevbd committed
32
- (void)didFailToRegisterForRemoteNotificationsWithError:(NSError *)error {
yogevbd's avatar
WIP  
yogevbd committed
33
    [_notificationEventHandler didFailToRegisterForRemoteNotificationsWithError:error];
34
}
Lidan Hifi's avatar
Lidan Hifi committed
35

yogevbd's avatar
WIP  
yogevbd committed
36 37 38 39 40 41
- (void)setBadgeForNotification:(NSDictionary *)notification {
    if ([[notification objectForKey:@"aps"] objectForKey:@"badge"]){
        [[UIApplication sharedApplication] setApplicationIconBadgeNumber:[[[notification objectForKey:@"aps"] objectForKey:@"badge"] intValue]];
    }
}

Lidan Hifi's avatar
Lidan Hifi committed
42
@end