RNBridgeModule.m 3.08 KB
Newer Older
yogevbd's avatar
WIP  
yogevbd committed
1 2
#import "RNBridgeModule.h"
#import "RNCommandsHandler.h"
3
#import "RCTConvert+RNNotifications.h"
4
#import "RNNotificationsStore.h"
yogevbd's avatar
WIP  
yogevbd committed
5
#import <React/RCTBridgeDelegate.h>
yogevbd's avatar
WIP  
yogevbd committed
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24

@implementation RNBridgeModule {
    RNCommandsHandler* _commandsHandler;
}

@synthesize bridge = _bridge;

RCT_EXPORT_MODULE();

- (instancetype)init {
    self = [super init];
    _commandsHandler = [[RNCommandsHandler alloc] init];
    return self;
}

+ (BOOL)requiresMainQueueSetup {
    return YES;
}

25 26
- (void)setBridge:(RCTBridge *)bridge {
    _bridge = bridge;
27 28 29
    if ([_bridge.launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey]) {
        [[RNNotificationsStore sharedInstance] setInitialNotification:[_bridge.launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey]];
    }
30 31
}

yogevbd's avatar
WIP  
yogevbd committed
32 33 34 35 36 37 38 39 40 41
#pragma mark - JS interface

RCT_EXPORT_METHOD(requestPermissionsWithCategories:(NSArray *)json) {
    [_commandsHandler requestPermissionsWithCategories:json];
}

RCT_EXPORT_METHOD(getInitialNotification:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject) {
    [_commandsHandler getInitialNotification:resolve reject:reject];
}

yogevbd's avatar
WIP  
yogevbd committed
42 43 44 45 46 47
RCT_EXPORT_METHOD(finishHandlingAction:(NSString *)completionKey) {
    [_commandsHandler finishHandlingAction:completionKey];
}

RCT_EXPORT_METHOD(finishPresentingNotification:(NSString *)completionKey presentingOptions:(NSDictionary *)presentingOptions) {
    [_commandsHandler finishPresentingNotification:completionKey presentingOptions:presentingOptions];
yogevbd's avatar
WIP  
yogevbd committed
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
}

RCT_EXPORT_METHOD(abandonPermissions) {
    [_commandsHandler abandonPermissions];
}

RCT_EXPORT_METHOD(registerPushKit) {
    [_commandsHandler registerPushKit];
}

RCT_EXPORT_METHOD(getBadgesCount:(RCTResponseSenderBlock)callback) {
    [_commandsHandler getBadgesCount:callback];
}

RCT_EXPORT_METHOD(setBadgesCount:(int)count) {
    [_commandsHandler setBadgesCount:count];
}

RCT_EXPORT_METHOD(localNotification:(NSDictionary *)notification withId:(NSString *)notificationId) {
yogevbd's avatar
WIP  
yogevbd committed
67
    [_commandsHandler sendLocalNotification:notification withId:notificationId];
yogevbd's avatar
WIP  
yogevbd committed
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
}

RCT_EXPORT_METHOD(cancelLocalNotification:(NSString *)notificationId) {
    [_commandsHandler cancelLocalNotification:notificationId];
}

RCT_EXPORT_METHOD(cancelAllLocalNotifications) {
    [_commandsHandler cancelAllLocalNotifications];
}

RCT_EXPORT_METHOD(isRegisteredForRemoteNotifications:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject) {
    [_commandsHandler isRegisteredForRemoteNotifications:resolve reject:reject];
}

RCT_EXPORT_METHOD(checkPermissions:(RCTPromiseResolveBlock)resolve
                  reject:(RCTPromiseRejectBlock)reject) {
    [_commandsHandler checkPermissions:resolve reject:reject];
}

#if !TARGET_OS_TV

RCT_EXPORT_METHOD(removeAllDeliveredNotifications) {
    [_commandsHandler removeAllDeliveredNotifications];
}

RCT_EXPORT_METHOD(removeDeliveredNotifications:(NSArray<NSString *> *)identifiers) {
    [_commandsHandler removeDeliveredNotifications:identifiers];
}

RCT_EXPORT_METHOD(getDeliveredNotifications:(RCTResponseSenderBlock)callback) {
    [_commandsHandler getDeliveredNotifications:callback];
}

#endif

@end