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

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
}

- (void)requestPermissionsWithCategories:(NSArray *)json {
yogevbd's avatar
WIP  
yogevbd committed
17
    [_notificationCenter requestPermissionsWithCategories:json];
yogevbd's avatar
WIP  
yogevbd committed
18 19 20
}

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

yogevbd's avatar
WIP  
yogevbd committed
24
- (void)finishHandlingAction:(NSString *)completionKey {
25
    [[RNNotificationsStore sharedInstance] completeAction:completionKey];
yogevbd's avatar
WIP  
yogevbd committed
26 27 28
}

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

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

- (void)registerPushKit {
yogevbd's avatar
yogevbd committed
37
    [RNNotifications startMonitorPushKitNotifications];
yogevbd's avatar
WIP  
yogevbd committed
38 39 40 41 42 43 44 45 46 47 48
}

- (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
49 50
- (void)sendLocalNotification:(NSDictionary *)notification withId:(NSString *)notificationId {
    [_notificationCenter sendLocalNotification:notification withId:notificationId];
yogevbd's avatar
WIP  
yogevbd committed
51 52 53
}

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

- (void)cancelAllLocalNotifications {
yogevbd's avatar
WIP  
yogevbd committed
58
    [_notificationCenter cancelAllLocalNotifications];
yogevbd's avatar
WIP  
yogevbd committed
59 60 61
}

- (void)isRegisteredForRemoteNotifications:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject {
yogevbd's avatar
WIP  
yogevbd committed
62
    [_notificationCenter isRegisteredForRemoteNotifications:resolve];
yogevbd's avatar
WIP  
yogevbd committed
63 64 65
}

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

- (void)removeAllDeliveredNotifications {
yogevbd's avatar
WIP  
yogevbd committed
70
    [_notificationCenter removeAllDeliveredNotifications];
yogevbd's avatar
WIP  
yogevbd committed
71 72 73
}

- (void)removeDeliveredNotifications:(NSArray<NSString *> *)identifiers {
yogevbd's avatar
WIP  
yogevbd committed
74
    [_notificationCenter removeDeliveredNotifications:identifiers];
yogevbd's avatar
WIP  
yogevbd committed
75 76 77
}

- (void)getDeliveredNotifications:(RCTResponseSenderBlock)callback {
yogevbd's avatar
WIP  
yogevbd committed
78
    [_notificationCenter getDeliveredNotifications:callback];
yogevbd's avatar
WIP  
yogevbd committed
79 80 81
}

@end