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

@implementation RNNotificationsStore {
yogevbd's avatar
WIP  
yogevbd committed
4
    NSMutableDictionary* _actionCompletionHandlers;
yogevbd's avatar
WIP  
yogevbd committed
5
    NSMutableDictionary* _presentationCompletionHandlers;
6 7 8
}

- (instancetype)init {
yogevbd's avatar
WIP  
yogevbd committed
9 10
    self = [super init];
    _actionCompletionHandlers = [NSMutableDictionary new];
yogevbd's avatar
WIP  
yogevbd committed
11
    _presentationCompletionHandlers = [NSMutableDictionary new];
12 13 14
    return self;
}

yogevbd's avatar
WIP  
yogevbd committed
15
- (void)setActionCompletionHandler:(void (^)())completionHandler withCompletionKey:(NSString *)completionKey {
yogevbd's avatar
WIP  
yogevbd committed
16 17 18
    _actionCompletionHandlers[completionKey] = completionHandler;
}

yogevbd's avatar
WIP  
yogevbd committed
19 20 21 22
- (void)setPresentationCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler withCompletionKey:(NSString *)completionKey {
    _presentationCompletionHandlers[completionKey] = completionHandler;
}

yogevbd's avatar
WIP  
yogevbd committed
23 24 25 26 27 28 29
- (void)completeAction:(NSString *)completionKey {
    void (^completionHandler)() = (void (^)())[_actionCompletionHandlers valueForKey:completionKey];
    if (completionHandler) {
        completionHandler();
        [_actionCompletionHandlers removeObjectForKey:completionKey];
    }
}
yogevbd's avatar
WIP  
yogevbd committed
30 31 32 33 34 35 36 37 38

- (void)completePresentation:(NSString *)completionKey withPresentationOptions:(UNNotificationPresentationOptions)presentationOptions {
    void (^completionHandler)() = (void (^)(UNNotificationPresentationOptions))[_presentationCompletionHandlers valueForKey:completionKey];
    if (completionHandler) {
        completionHandler(presentationOptions);
        [_actionCompletionHandlers removeObjectForKey:completionKey];
    }
}

39
@end