Commit 25c9c400 authored by Lidan Hifi's avatar Lidan Hifi

fix bug- trigger notification opened event on app launch

parent 97ed9e39
......@@ -142,6 +142,9 @@ RCT_EXPORT_MODULE()
selector:@selector(handleNotificationActionTriggered:)
name:RNNotificationActionTriggered
object:nil];
[RNNotificationsBridgeQueue sharedInstance].openedRemoteNotification = [_bridge.launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
[RNNotificationsBridgeQueue sharedInstance].openedLocalNotification = [_bridge.launchOptions objectForKey:UIApplicationLaunchOptionsLocalNotificationKey];
}
/*
......@@ -165,6 +168,9 @@ RCT_EXPORT_MODULE()
{
UIApplicationState state = [UIApplication sharedApplication].applicationState;
if ([RNNotificationsBridgeQueue sharedInstance].jsIsReady == YES) {
// JS thread is ready, push the notification to the bridge
if (state == UIApplicationStateActive) {
// Notification received foreground
[self didReceiveNotificationOnForegroundState:notification];
......@@ -175,6 +181,10 @@ RCT_EXPORT_MODULE()
// Notification received background
[self didReceiveNotificationOnBackgroundState:notification];
}
} else {
// JS thread is not ready - store it in the native notifications queue
[[RNNotificationsBridgeQueue sharedInstance] postNotification:notification];
}
}
+ (void)didReceiveLocalNotification:(UILocalNotification *)notification
......@@ -231,14 +241,9 @@ RCT_EXPORT_MODULE()
}
}
// if Js thread is ready- post notification to bridge. otherwise- post it to the bridge queue
if ([RNNotificationsBridgeQueue sharedInstance].jsIsReady == YES) {
[[NSNotificationCenter defaultCenter] postNotificationName:RNNotificationReceivedBackground
object:self
userInfo:notification];
} else {
[[RNNotificationsBridgeQueue sharedInstance] postNotification:notification];
}
}
+ (void)didNotificationOpen:(NSDictionary *)notification
......@@ -450,19 +455,32 @@ RCT_EXPORT_METHOD(backgroundTimeRemaining:(RCTResponseSenderBlock)callback)
RCT_EXPORT_METHOD(consumeBackgroundQueue)
{
// Mark JS Thread as ready
[RNNotificationsBridgeQueue sharedInstance].jsIsReady = YES;
// Push actions to JS
[[RNNotificationsBridgeQueue sharedInstance] consumeActionsQueue:^(NSDictionary* action) {
[[NSNotificationCenter defaultCenter] postNotificationName:RNNotificationActionTriggered
object:self
userInfo:action];
}];
// Push background notifications to JS
[[RNNotificationsBridgeQueue sharedInstance] consumeNotificationsQueue:^(NSDictionary* notification) {
[[NSNotificationCenter defaultCenter] postNotificationName:RNNotificationReceivedBackground
object:self
userInfo:notification];
[RNNotifications didReceiveRemoteNotification:notification];
}];
[RNNotificationsBridgeQueue sharedInstance].jsIsReady = YES;
// Push opened local notifications
NSDictionary* openedLocalNotification = [RNNotificationsBridgeQueue sharedInstance].openedLocalNotification;
if (openedLocalNotification) {
[RNNotifications didNotificationOpen:openedLocalNotification];
}
// Push opened remote notifications
NSDictionary* openedRemoteNotification = [RNNotificationsBridgeQueue sharedInstance].openedRemoteNotification;
if (openedRemoteNotification) {
[RNNotifications didNotificationOpen:openedRemoteNotification];
}
}
RCT_EXPORT_METHOD(localNotification:(NSDictionary *)notification)
......
......@@ -3,8 +3,11 @@
@interface RNNotificationsBridgeQueue : NSObject
@property BOOL jsIsReady;
@property NSDictionary* openedRemoteNotification;
@property NSDictionary* openedLocalNotification;
+ (nonnull instancetype)sharedInstance;
- (void)postAction:(NSDictionary *)action withCompletionKey:(NSString *)completionKey andCompletionHandler:(void (^)())completionHandler;
- (void)postNotification:(NSDictionary *)notification;
......
......@@ -3,7 +3,7 @@
@implementation RNNotificationsBridgeQueue
NSMutableArray<NSDictionary *>* actionsQueue;
NSMutableArray<NSDictionary *>* backgroundNotificationsQueue;
NSMutableArray<NSDictionary *>* notificationsQueue;
NSMutableDictionary* actionCompletionHandlers;
+ (nonnull instancetype)sharedInstance {
......@@ -19,7 +19,7 @@ NSMutableDictionary* actionCompletionHandlers;
- (instancetype)init
{
actionsQueue = [NSMutableArray new];
backgroundNotificationsQueue = [NSMutableArray new];
notificationsQueue = [NSMutableArray new];
actionCompletionHandlers = [NSMutableDictionary new];
self.jsIsReady = NO;
......@@ -28,16 +28,16 @@ NSMutableDictionary* actionCompletionHandlers;
- (void)postNotification:(NSDictionary *)notification
{
if (!backgroundNotificationsQueue) return;
[backgroundNotificationsQueue insertObject:notification atIndex:0];
if (!notificationsQueue) return;
[notificationsQueue insertObject:notification atIndex:0];
}
- (NSDictionary *)dequeueSingleNotification
{
if (!backgroundNotificationsQueue || backgroundNotificationsQueue.count == 0) return nil;
if (!notificationsQueue || notificationsQueue.count == 0) return nil;
NSDictionary* notification = [backgroundNotificationsQueue lastObject];
[backgroundNotificationsQueue removeLastObject];
NSDictionary* notification = [notificationsQueue lastObject];
[notificationsQueue removeLastObject];
return notification;
}
......@@ -50,7 +50,7 @@ NSMutableDictionary* actionCompletionHandlers;
block(notification);
}
backgroundNotificationsQueue = nil;
notificationsQueue = nil;
}
- (void)postAction:(NSDictionary *)action withCompletionKey:(NSString *)completionKey andCompletionHandler:(void (^)())completionHandler
......
......@@ -691,6 +691,7 @@
OTHER_LDFLAGS = "-ObjC";
PRODUCT_BUNDLE_IDENTIFIER = "com.wix.smart-notifications-test-app";
PRODUCT_NAME = NotificationsExampleApp;
PROVISIONING_PROFILE = "";
};
name = Debug;
};
......@@ -710,6 +711,7 @@
OTHER_LDFLAGS = "-ObjC";
PRODUCT_BUNDLE_IDENTIFIER = "com.wix.smart-notifications-test-app";
PRODUCT_NAME = NotificationsExampleApp;
PROVISIONING_PROFILE = "";
};
name = Release;
};
......@@ -730,6 +732,7 @@
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
CODE_SIGN_IDENTITY = "iPhone Developer";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
COPY_PHASE_STRIP = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES;
......@@ -777,6 +780,7 @@
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
CODE_SIGN_IDENTITY = "iPhone Developer";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
COPY_PHASE_STRIP = YES;
ENABLE_NS_ASSERTIONS = NO;
......
......@@ -33,7 +33,7 @@
* on the same Wi-Fi network.
*/
jsCodeLocation = [NSURL URLWithString:@"http://192.168.1.15:8081/index.ios.bundle?platform=ios&dev=true"];
jsCodeLocation = [NSURL URLWithString:@"http://172.31.9.91:8081/index.ios.bundle?platform=ios&dev=true"];
/**
* OPTION 2
......
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