Commit e819748f authored by yogevbd's avatar yogevbd

WIP

parent 5c2c649d
......@@ -11,7 +11,6 @@
- (instancetype)initWithStore:(RNNotificationsStore *)store {
self = [super init];
_store = store;
return self;
}
......
#import "RCTEventEmitter.h"
static NSString* const RNRegistered = @"RNNotificationsRegistered";
static NSString* const RNRegistrationFailed = @"RNNotificationsRegistrationFailed";
static NSString* const RNPushKitRegistered = @"RNPushKitRegistered";
static NSString* const RNNotificationReceivedForeground = @"RNNotificationReceivedForeground";
static NSString* const RNNotificationReceivedBackground = @"RNNotificationReceivedBackground";
static NSString* const RNNotificationOpened = @"RNNotificationOpened";
static NSString* const RNActionTriggered = @"RNNotificationActionTriggered";
static NSString* const RNRegistered = @"notificationsRegistered";
static NSString* const RNRegistrationFailed = @"notificationsRegistrationFailed";
static NSString* const RNPushKitRegistered = @"pushKitRegistered";
static NSString* const RNNotificationReceivedForeground = @"notificationReceivedForeground";
static NSString* const RNNotificationReceivedBackground = @"notificationReceivedBackground";
static NSString* const RNNotificationOpened = @"notificationOpened";
static NSString* const RNActionTriggered = @"notificationActionTriggered";
@interface RNEventEmitter : RCTEventEmitter
......
......@@ -6,6 +6,9 @@
- (instancetype)initWithStore:(RNNotificationsStore *)store;
- (void)didRegisterForRemoteNotificationsWithDeviceToken:(id)deviceToken;
- (void)didFailToRegisterForRemoteNotificationsWithError:(NSError *)error;
- (void)didReceiveForegroundPayload:(NSDictionary *)payload;
- (void)didOpenNotificationPayload:(NSDictionary *)payload;
- (void)handleActionWithIdentifier:(NSString *)identifier forPayload:(NSDictionary *)payload withResponse:(NSString *)response completionHandler:(void (^)())completionHandler;
......
#import "RNNotificationEventHandler.h"
#import "RNEventEmitter.h"
#import "RNUtils.h"
@implementation RNNotificationEventHandler {
RNNotificationsStore* _store;
......@@ -8,10 +9,18 @@
- (instancetype)initWithStore:(RNNotificationsStore *)store {
self = [super init];
_store = store;
return self;
}
- (void)didRegisterForRemoteNotificationsWithDeviceToken:(id)deviceToken {
NSString *tokenRepresentation = [deviceToken isKindOfClass:[NSString class]] ? deviceToken : [RNUtils deviceTokenToString:deviceToken];
[RNEventEmitter sendEvent:RNRegistered body:@{@"deviceToken": tokenRepresentation}];
}
- (void)didFailToRegisterForRemoteNotificationsWithError:(NSError *)error {
[RNEventEmitter sendEvent:RNRegistrationFailed body:@{@"code": [NSNumber numberWithInteger:error.code], @"domain": error.domain, @"localizedDescription": error.localizedDescription}];
}
- (void)didReceiveForegroundPayload:(NSDictionary *)payload {
[RNEventEmitter sendEvent:RNNotificationReceivedForeground body:payload];
}
......
......@@ -2,20 +2,12 @@
#import <UIKit/UIKit.h>
#import <PushKit/PushKit.h>
#import <React/RCTBridge.h>
#import <React/RCTEventDispatcher.h>
#import "RNNotifications.h"
#import <React/RCTConvert.h>
#import <React/RCTUtils.h>
#import <UserNotifications/UserNotifications.h>
#import "RNEventEmitter.h"
#import "RNNotificationCenterListener.h"
#import "RNUtils.h"
NSString* const RNNotificationCreateAction = @"CREATE";
NSString* const RNNotificationClearAction = @"CLEAR";
@implementation RNNotifications {
RNNotificationCenterListener* _notificationCenterListener;
RNNotificationEventHandler* _notificationEventHandler;
}
+ (instancetype)sharedInstance {
......@@ -29,17 +21,16 @@ NSString* const RNNotificationClearAction = @"CLEAR";
}
- (void)initialize {
RNNotificationEventHandler* notificationEventHandler = [RNNotificationEventHandler new];
_notificationCenterListener = [[RNNotificationCenterListener alloc] initWithNotificationEventHandler:notificationEventHandler];
_notificationEventHandler = [RNNotificationEventHandler new];
_notificationCenterListener = [[RNNotificationCenterListener alloc] initWithNotificationEventHandler:_notificationEventHandler];
}
- (void)didRegisterForRemoteNotificationsWithDeviceToken:(id)deviceToken {
NSString *tokenRepresentation = [deviceToken isKindOfClass:[NSString class]] ? deviceToken : [RNUtils deviceTokenToString:deviceToken];
[RNEventEmitter sendEvent:RNRegistered body:@{@"deviceToken": tokenRepresentation}];
[_notificationEventHandler didRegisterForRemoteNotificationsWithDeviceToken:deviceToken];
}
- (void)didFailToRegisterForRemoteNotificationsWithError:(NSError *)error {
[RNEventEmitter sendEvent:RNRegistrationFailed body:@{@"code": [NSNumber numberWithInteger:error.code], @"domain": error.domain, @"localizedDescription": error.localizedDescription}];
[_notificationEventHandler didFailToRegisterForRemoteNotificationsWithError:error];
}
- (void)setBadgeForNotification:(NSDictionary *)notification {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment