Skip to content
This repository was archived by the owner on Sep 24, 2021. It is now read-only.

Commit d4edbe4

Browse files
committed
fix(ios): treat events when app is inactive as background events
1 parent 1da3f3c commit d4edbe4

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

ios/RNNotifee/NotifeeApiModule.m

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ - (id)init {
5555
- (void)startObserving {
5656
hasListeners = YES;
5757
for (NSDictionary *eventBody in pendingCoreEvents) {
58-
[self sendNotifeeCoreEvent:eventBody];
58+
BOOL *foreground = [UIApplication sharedApplication].applicationState == UIApplicationStateActive;
59+
[self sendNotifeeCoreEvent:eventBody foreground: foreground];
5960
}
6061
[pendingCoreEvents removeAllObjects];
6162
}
@@ -70,26 +71,24 @@ + (BOOL)requiresMainQueueSetup {
7071

7172
#pragma mark - Events
7273

73-
- (void)didReceiveNotifeeCoreEvent:(NSDictionary *_Nonnull)event {
74+
- (void)didReceiveNotifeeCoreEvent:(NSDictionary *_Nonnull)event foreground: (BOOL)foreground; {
7475
if (hasListeners) {
75-
[self sendNotifeeCoreEvent:event];
76+
[self sendNotifeeCoreEvent:event foreground:foreground];
7677
} else {
7778
[pendingCoreEvents addObject:event];
7879
}
7980
}
8081

81-
- (void)sendNotifeeCoreEvent:(NSDictionary *_Nonnull)eventBody {
82+
- (void)sendNotifeeCoreEvent:(NSDictionary *_Nonnull)eventBody foreground: (BOOL)foreground; {
8283
dispatch_after(
8384
dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
84-
if (RCTRunningInAppExtension() ||
85-
[UIApplication sharedApplication].applicationState == UIApplicationStateBackground) {
85+
if (RCTRunningInAppExtension() || !foreground ) {
8686
[self sendEventWithName:kReactNativeNotifeeNotificationBackgroundEvent body:eventBody];
8787
} else {
8888
[self sendEventWithName:kReactNativeNotifeeNotificationEvent body:eventBody];
8989
}
9090
});
9191
}
92-
9392
// TODO(helenaford): look into a custom format style for React Native Method signatures
9493
// clang-format off
9594

0 commit comments

Comments
 (0)