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

#import <UIKit/UIKit.h>
3
#import <PushKit/PushKit.h>
4 5 6 7 8
#import <React/RCTBridge.h>
#import <React/RCTEventDispatcher.h>
#import "RNNotifications.h"
#import <React/RCTConvert.h>
#import <React/RCTUtils.h>
9
#import "RNNotificationsBridgeQueue.h"
10
#import <UserNotifications/UserNotifications.h>
yogevbd's avatar
WIP  
yogevbd committed
11
#import "RNEventEmitter.h"
12 13
#import "RNNotificationEventHandler.h"
#import "RNUtils.h"
14

15 16
NSString* const RNNotificationCreateAction = @"CREATE";
NSString* const RNNotificationClearAction = @"CLEAR";
Lidan Hifi's avatar
Lidan Hifi committed
17

18 19 20
@implementation RNNotifications {
    RNNotificationEventHandler* _notificationEventHandler;
}
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;
}

32 33
- (void)initialize {
    _notificationEventHandler = [RNNotificationEventHandler new];
Artal Druk's avatar
Artal Druk committed
34
}
35

yogevbd's avatar
WIP  
yogevbd committed
36
- (void)didRegisterForRemoteNotificationsWithDeviceToken:(id)deviceToken {
37
    NSString *tokenRepresentation = [deviceToken isKindOfClass:[NSString class]] ? deviceToken : [RNUtils deviceTokenToString:deviceToken];
yogevbd's avatar
WIP  
yogevbd committed
38
    [RNEventEmitter sendEvent:Registered body:@{@"deviceToken": tokenRepresentation}];
39
}
Lidan Hifi's avatar
Lidan Hifi committed
40

yogevbd's avatar
WIP  
yogevbd committed
41 42
- (void)didFailToRegisterForRemoteNotificationsWithError:(NSError *)error {
    [RNEventEmitter sendEvent:RegistrationFailed body:@{@"code": [NSNumber numberWithInteger:error.code], @"domain": error.domain, @"localizedDescription": error.localizedDescription}];
43
}
Lidan Hifi's avatar
Lidan Hifi committed
44

yogevbd's avatar
WIP  
yogevbd committed
45 46 47 48 49 50
- (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
51
@end