RNNotificationsStore.m 1.98 KB
Newer Older
1 2
#import "RNNotificationsStore.h"

3 4 5 6 7 8 9 10 11 12 13 14
@implementation RNNotificationsStore
NSMutableDictionary* _actionCompletionHandlers;
NSMutableDictionary* _presentationCompletionHandlers;

+ (instancetype)sharedInstance {
    static RNNotificationsStore *sharedInstance = nil;
    static dispatch_once_t onceToken;
    
    dispatch_once(&onceToken, ^{
        sharedInstance = [[RNNotificationsStore alloc] init];
    });
    return sharedInstance;
15 16 17
}

- (instancetype)init {
yogevbd's avatar
WIP  
yogevbd committed
18 19
    self = [super init];
    _actionCompletionHandlers = [NSMutableDictionary new];
yogevbd's avatar
WIP  
yogevbd committed
20
    _presentationCompletionHandlers = [NSMutableDictionary new];
21 22 23
    return self;
}

yogevbd's avatar
yogevbd committed
24
- (void)setActionCompletionHandler:(void (^)(void))completionHandler withCompletionKey:(NSString *)completionKey {
yogevbd's avatar
WIP  
yogevbd committed
25 26 27
    _actionCompletionHandlers[completionKey] = completionHandler;
}

yogevbd's avatar
WIP  
yogevbd committed
28 29 30 31
- (void)setPresentationCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler withCompletionKey:(NSString *)completionKey {
    _presentationCompletionHandlers[completionKey] = completionHandler;
}

yogevbd's avatar
yogevbd committed
32 33 34 35 36 37 38 39
- (void (^)(void))getActionCompletionHandler:(NSString *)key {
    return _actionCompletionHandlers[key];
}

- (void (^)(UNNotificationPresentationOptions))getPresentationCompletionHandler:(NSString *)key {
    return _presentationCompletionHandlers[key];
}

yogevbd's avatar
WIP  
yogevbd committed
40 41 42 43 44 45 46
- (void)completeAction:(NSString *)completionKey {
    void (^completionHandler)() = (void (^)())[_actionCompletionHandlers valueForKey:completionKey];
    if (completionHandler) {
        completionHandler();
        [_actionCompletionHandlers removeObjectForKey:completionKey];
    }
}
yogevbd's avatar
WIP  
yogevbd committed
47 48 49 50 51

- (void)completePresentation:(NSString *)completionKey withPresentationOptions:(UNNotificationPresentationOptions)presentationOptions {
    void (^completionHandler)() = (void (^)(UNNotificationPresentationOptions))[_presentationCompletionHandlers valueForKey:completionKey];
    if (completionHandler) {
        completionHandler(presentationOptions);
yogevbd's avatar
yogevbd committed
52
        [_presentationCompletionHandlers removeObjectForKey:completionKey];
yogevbd's avatar
WIP  
yogevbd committed
53 54 55
    }
}

56
@end