Files
react-native-notifications/RNNotifications/RNNotifications.m
yogevbd 235cffd8a4 WIP
2019-07-09 00:42:38 +03:00

71 lines
2.3 KiB
Objective-C

#import <UIKit/UIKit.h>
#import <PushKit/PushKit.h>
#import <React/RCTBridge.h>
#import "RNNotifications.h"
#import "RNNotificationCenterListener.h"
#import "RNPushKit.h"
@implementation RNNotifications {
RNPushKit* _pushKit;
RNNotificationCenterListener* _notificationCenterListener;
RNNotificationEventHandler* _notificationEventHandler;
RNPushKitEventHandler* _pushKitEventHandler;
RNEventEmitter* _eventEmitter;
RNNotificationsStore* _store;
}
- (instancetype)init {
self = [super init];
_store = [RNNotificationsStore new];
return self;
}
+ (instancetype)sharedInstance {
static RNNotifications *sharedInstance = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
sharedInstance = [[RNNotifications alloc] init];
});
return sharedInstance;
}
- (void)initialize {
_notificationEventHandler = [[RNNotificationEventHandler alloc] initWithStore:_store];
_notificationCenterListener = [[RNNotificationCenterListener alloc] initWithNotificationEventHandler:_notificationEventHandler];
}
- (void)initializePushKit {
_pushKitEventHandler = [RNPushKitEventHandler new];
_pushKit = [[RNPushKit alloc] initWithEventHandler:_pushKitEventHandler];
}
- (void)didRegisterForRemoteNotificationsWithDeviceToken:(id)deviceToken {
[_notificationEventHandler didRegisterForRemoteNotificationsWithDeviceToken:deviceToken];
}
- (void)didFailToRegisterForRemoteNotificationsWithError:(NSError *)error {
[_notificationEventHandler didFailToRegisterForRemoteNotificationsWithError:error];
}
- (void)setBadgeForNotification:(NSDictionary *)notification {
if ([[notification objectForKey:@"aps"] objectForKey:@"badge"]){
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:[[[notification objectForKey:@"aps"] objectForKey:@"badge"] intValue]];
}
}
- (void)setInitialNotification:(NSDictionary *)notification {
[_store setInitialNotification:notification];
}
- (void)finishHandleActionKey:(NSString *)actionKey {
[_store completeAction:actionKey];
}
- (void)finishHandleNotificationKey:(NSString *)notificationKey presentingOptions:(UNNotificationPresentationOptions)presentingOptions {
[_store completePresentation:notificationKey withPresentationOptions:presentingOptions];
}
@end