RNCommandsHandler.m 2.7 KB
Newer Older
yogevbd's avatar
WIP  
yogevbd committed
1 2
#import "RNCommandsHandler.h"
#import "RNNotifications.h"
3
#import "RNNotificationsStore.h"
4
#import "RCTConvert+RNNotifications.h"
yogevbd's avatar
WIP  
yogevbd committed
5

6
@implementation RNCommandsHandler {
yogevbd's avatar
WIP  
yogevbd committed
7 8 9 10 11 12 13
    RNNotificationCenter* _notificationCenter;
}

- (instancetype)init {
    self = [super init];
    _notificationCenter = [RNNotificationCenter new];
    return self;
yogevbd's avatar
WIP  
yogevbd committed
14 15
}

16 17 18 19 20 21
- (void)requestPermissions {
    [_notificationCenter requestPermissions];
}

- (void)setCategories:(NSArray *)categories {
    [_notificationCenter setCategories:categories];
yogevbd's avatar
WIP  
yogevbd committed
22 23 24
}

- (void)getInitialNotification:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject {
25
    resolve([[RNNotificationsStore sharedInstance] initialNotification]);
yogevbd's avatar
WIP  
yogevbd committed
26 27
}

yogevbd's avatar
WIP  
yogevbd committed
28
- (void)finishHandlingAction:(NSString *)completionKey {
29
    [[RNNotificationsStore sharedInstance] completeAction:completionKey];
yogevbd's avatar
WIP  
yogevbd committed
30 31 32
}

- (void)finishPresentingNotification:(NSString *)completionKey presentingOptions:(NSDictionary *)presentingOptions {
33
    [[RNNotificationsStore sharedInstance] completePresentation:completionKey withPresentationOptions:[RCTConvert UNNotificationPresentationOptions:presentingOptions]];
yogevbd's avatar
WIP  
yogevbd committed
34 35 36 37 38 39 40
}

- (void)abandonPermissions {
    [[UIApplication sharedApplication] unregisterForRemoteNotifications];
}

- (void)registerPushKit {
yogevbd's avatar
yogevbd committed
41
    [RNNotifications startMonitorPushKitNotifications];
yogevbd's avatar
WIP  
yogevbd committed
42 43 44 45 46 47 48 49 50 51 52
}

- (void)getBadgesCount:(RCTResponseSenderBlock)callback {
    NSInteger count = [UIApplication sharedApplication].applicationIconBadgeNumber;
    callback(@[ [NSNumber numberWithInteger:count] ]);
}

- (void)setBadgesCount:(int)count {
    [[UIApplication sharedApplication] setApplicationIconBadgeNumber:count];
}

yogevbd's avatar
WIP  
yogevbd committed
53 54
- (void)sendLocalNotification:(NSDictionary *)notification withId:(NSString *)notificationId {
    [_notificationCenter sendLocalNotification:notification withId:notificationId];
yogevbd's avatar
WIP  
yogevbd committed
55 56 57
}

- (void)cancelLocalNotification:(NSString *)notificationId {
yogevbd's avatar
WIP  
yogevbd committed
58
    [_notificationCenter cancelLocalNotification:notificationId];
yogevbd's avatar
WIP  
yogevbd committed
59 60 61
}

- (void)cancelAllLocalNotifications {
yogevbd's avatar
WIP  
yogevbd committed
62
    [_notificationCenter cancelAllLocalNotifications];
yogevbd's avatar
WIP  
yogevbd committed
63 64 65
}

- (void)isRegisteredForRemoteNotifications:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject {
yogevbd's avatar
WIP  
yogevbd committed
66
    [_notificationCenter isRegisteredForRemoteNotifications:resolve];
yogevbd's avatar
WIP  
yogevbd committed
67 68 69
}

- (void)checkPermissions:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject {
yogevbd's avatar
WIP  
yogevbd committed
70
    [_notificationCenter checkPermissions:resolve];
yogevbd's avatar
WIP  
yogevbd committed
71 72 73
}

- (void)removeAllDeliveredNotifications {
yogevbd's avatar
WIP  
yogevbd committed
74
    [_notificationCenter removeAllDeliveredNotifications];
yogevbd's avatar
WIP  
yogevbd committed
75 76 77
}

- (void)removeDeliveredNotifications:(NSArray<NSString *> *)identifiers {
yogevbd's avatar
WIP  
yogevbd committed
78
    [_notificationCenter removeDeliveredNotifications:identifiers];
yogevbd's avatar
WIP  
yogevbd committed
79 80 81
}

- (void)getDeliveredNotifications:(RCTResponseSenderBlock)callback {
yogevbd's avatar
WIP  
yogevbd committed
82
    [_notificationCenter getDeliveredNotifications:callback];
yogevbd's avatar
WIP  
yogevbd committed
83 84 85
}

@end