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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

@end