RNNotificationsStore.m 1.72 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
WIP  
yogevbd committed
24
- (void)setActionCompletionHandler:(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
WIP  
yogevbd committed
32 33 34 35 36 37 38
- (void)completeAction:(NSString *)completionKey {
    void (^completionHandler)() = (void (^)())[_actionCompletionHandlers valueForKey:completionKey];
    if (completionHandler) {
        completionHandler();
        [_actionCompletionHandlers removeObjectForKey:completionKey];
    }
}
yogevbd's avatar
WIP  
yogevbd committed
39 40 41 42 43 44 45 46 47

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

48
@end