Commit e819748f authored by yogevbd's avatar yogevbd

WIP

parent 5c2c649d
...@@ -11,7 +11,6 @@ ...@@ -11,7 +11,6 @@
- (instancetype)initWithStore:(RNNotificationsStore *)store { - (instancetype)initWithStore:(RNNotificationsStore *)store {
self = [super init]; self = [super init];
_store = store; _store = store;
return self; return self;
} }
......
#import "RCTEventEmitter.h" #import "RCTEventEmitter.h"
static NSString* const RNRegistered = @"RNNotificationsRegistered"; static NSString* const RNRegistered = @"notificationsRegistered";
static NSString* const RNRegistrationFailed = @"RNNotificationsRegistrationFailed"; static NSString* const RNRegistrationFailed = @"notificationsRegistrationFailed";
static NSString* const RNPushKitRegistered = @"RNPushKitRegistered"; static NSString* const RNPushKitRegistered = @"pushKitRegistered";
static NSString* const RNNotificationReceivedForeground = @"RNNotificationReceivedForeground"; static NSString* const RNNotificationReceivedForeground = @"notificationReceivedForeground";
static NSString* const RNNotificationReceivedBackground = @"RNNotificationReceivedBackground"; static NSString* const RNNotificationReceivedBackground = @"notificationReceivedBackground";
static NSString* const RNNotificationOpened = @"RNNotificationOpened"; static NSString* const RNNotificationOpened = @"notificationOpened";
static NSString* const RNActionTriggered = @"RNNotificationActionTriggered"; static NSString* const RNActionTriggered = @"notificationActionTriggered";
@interface RNEventEmitter : RCTEventEmitter @interface RNEventEmitter : RCTEventEmitter
......
...@@ -6,6 +6,9 @@ ...@@ -6,6 +6,9 @@
- (instancetype)initWithStore:(RNNotificationsStore *)store; - (instancetype)initWithStore:(RNNotificationsStore *)store;
- (void)didRegisterForRemoteNotificationsWithDeviceToken:(id)deviceToken;
- (void)didFailToRegisterForRemoteNotificationsWithError:(NSError *)error;
- (void)didReceiveForegroundPayload:(NSDictionary *)payload; - (void)didReceiveForegroundPayload:(NSDictionary *)payload;
- (void)didOpenNotificationPayload:(NSDictionary *)payload; - (void)didOpenNotificationPayload:(NSDictionary *)payload;
- (void)handleActionWithIdentifier:(NSString *)identifier forPayload:(NSDictionary *)payload withResponse:(NSString *)response completionHandler:(void (^)())completionHandler; - (void)handleActionWithIdentifier:(NSString *)identifier forPayload:(NSDictionary *)payload withResponse:(NSString *)response completionHandler:(void (^)())completionHandler;
......
#import "RNNotificationEventHandler.h" #import "RNNotificationEventHandler.h"
#import "RNEventEmitter.h" #import "RNEventEmitter.h"
#import "RNUtils.h"
@implementation RNNotificationEventHandler { @implementation RNNotificationEventHandler {
RNNotificationsStore* _store; RNNotificationsStore* _store;
...@@ -8,10 +9,18 @@ ...@@ -8,10 +9,18 @@
- (instancetype)initWithStore:(RNNotificationsStore *)store { - (instancetype)initWithStore:(RNNotificationsStore *)store {
self = [super init]; self = [super init];
_store = store; _store = store;
return self; 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 { - (void)didReceiveForegroundPayload:(NSDictionary *)payload {
[RNEventEmitter sendEvent:RNNotificationReceivedForeground body:payload]; [RNEventEmitter sendEvent:RNNotificationReceivedForeground body:payload];
} }
......
...@@ -2,20 +2,12 @@ ...@@ -2,20 +2,12 @@
#import <UIKit/UIKit.h> #import <UIKit/UIKit.h>
#import <PushKit/PushKit.h> #import <PushKit/PushKit.h>
#import <React/RCTBridge.h> #import <React/RCTBridge.h>
#import <React/RCTEventDispatcher.h>
#import "RNNotifications.h" #import "RNNotifications.h"
#import <React/RCTConvert.h>
#import <React/RCTUtils.h>
#import <UserNotifications/UserNotifications.h>
#import "RNEventEmitter.h"
#import "RNNotificationCenterListener.h" #import "RNNotificationCenterListener.h"
#import "RNUtils.h"
NSString* const RNNotificationCreateAction = @"CREATE";
NSString* const RNNotificationClearAction = @"CLEAR";
@implementation RNNotifications { @implementation RNNotifications {
RNNotificationCenterListener* _notificationCenterListener; RNNotificationCenterListener* _notificationCenterListener;
RNNotificationEventHandler* _notificationEventHandler;
} }
+ (instancetype)sharedInstance { + (instancetype)sharedInstance {
...@@ -29,17 +21,16 @@ NSString* const RNNotificationClearAction = @"CLEAR"; ...@@ -29,17 +21,16 @@ NSString* const RNNotificationClearAction = @"CLEAR";
} }
- (void)initialize { - (void)initialize {
RNNotificationEventHandler* notificationEventHandler = [RNNotificationEventHandler new]; _notificationEventHandler = [RNNotificationEventHandler new];
_notificationCenterListener = [[RNNotificationCenterListener alloc] initWithNotificationEventHandler:notificationEventHandler]; _notificationCenterListener = [[RNNotificationCenterListener alloc] initWithNotificationEventHandler:_notificationEventHandler];
} }
- (void)didRegisterForRemoteNotificationsWithDeviceToken:(id)deviceToken { - (void)didRegisterForRemoteNotificationsWithDeviceToken:(id)deviceToken {
NSString *tokenRepresentation = [deviceToken isKindOfClass:[NSString class]] ? deviceToken : [RNUtils deviceTokenToString:deviceToken]; [_notificationEventHandler didRegisterForRemoteNotificationsWithDeviceToken:deviceToken];
[RNEventEmitter sendEvent:RNRegistered body:@{@"deviceToken": tokenRepresentation}];
} }
- (void)didFailToRegisterForRemoteNotificationsWithError:(NSError *)error { - (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 { - (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