Skip to content

Commit 20608e6

Browse files
authored
iOS show notification UI when app is in foreground and sdk is not initialized (#108)
1 parent 7e7b8ef commit 20608e6

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

ios/src/CountlyRNPushNotifications.m

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,26 @@ - (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNoti
143143
// When app is running and notification received
144144
- (void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler{
145145
[self onNotification: notification.request.content.userInfo];
146-
completionHandler(0);
146+
NSDictionary* countlyPayload = notification.request.content.userInfo[kCountlyPNKeyCountlyPayload];
147+
NSString* notificationID = countlyPayload[kCountlyPNKeyNotificationID];
148+
149+
if (notificationID)
150+
{
151+
UNNotificationPresentationOptions presentationOption = UNNotificationPresentationOptionNone;
152+
if (@available(iOS 14.0, tvOS 14.0, macOS 11.0, watchOS 7.0, *))
153+
{
154+
presentationOption = UNNotificationPresentationOptionList | UNNotificationPresentationOptionBanner;
155+
}
156+
else
157+
{
158+
#pragma GCC diagnostic push
159+
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
160+
presentationOption = UNNotificationPresentationOptionAlert;
161+
#pragma GCC diagnostic pop
162+
}
163+
completionHandler(presentationOption);
164+
}
165+
completionHandler(UNNotificationPresentationOptionNone);
147166
}
148167

149168
- (void)onNotification:(NSDictionary *)notificationMessage

0 commit comments

Comments
 (0)