[fcm] Start considering multiple events

This commit is contained in:
Chris Bianca 2018-02-16 09:47:46 +00:00
parent 9255b4be10
commit b86d51f36b
2 changed files with 35 additions and 8 deletions

View File

@ -38,6 +38,11 @@ static NSString *const MESSAGING_TOKEN_REFRESHED = @"messaging_token_refreshed";
// TODO: Remove
static NSString *const MESSAGING_NOTIFICATION_RECEIVED = @"messaging_notification_received";
// Notifications
static NSString *const NOTIFICATIONS_NOTIFICATION_CLICKED = @"notifications_notification_clicked";
static NSString *const NOTIFICATIONS_NOTIFICATION_DISPLAYED = @"notifications_notification_displayed";
static NSString *const NOTIFICATIONS_NOTIFICATION_RECEIVED = @"notifications_notification_received";
// AdMob
static NSString *const ADMOB_INTERSTITIAL_EVENT = @"interstitial_event";
static NSString *const ADMOB_REWARDED_VIDEO_EVENT = @"rewarded_video_event";

View File

@ -113,11 +113,34 @@ RCT_EXPORT_MODULE()
- (void)userNotificationCenter:(UNUserNotificationCenter *)center
willPresentNotification:(UNNotification *)notification
withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler {
NSString *event;
UNNotificationPresentationOptions options;
NSDictionary *message = [self parseUNNotification:notification messageType:@"PresentNotification" openedFromTray:false];
[_callbackHandlers setObject:[completionHandler copy] forKey:message[@"messageId"]];
[RNFirebaseUtil sendJSEvent:self name:MESSAGING_MESSAGE_RECEIVED body:message];
if (isFCM || isScheduled) {
// If background
if (RCTSharedApplication().applicationState == UIApplicationStateInactive) {
// display notification
options = UNNotificationPresentationOptionAlert | UNNotificationPresentationOptionBadge | UNNotificationPresentationOptionSound;
// notification_displayed
event = NOTIFICATIONS_NOTIFICATION_DISPLAYED;
} else {
// don't show notification
options = UNNotificationPresentationOptionNone;
// notification_received
event = NOTIFICATIONS_NOTIFICATION_RECEIVED;
}
} else {
// display notification
options = UNNotificationPresentationOptionAlert | UNNotificationPresentationOptionBadge | UNNotificationPresentationOptionSound;
// no event
}
if (event) {
[RNFirebaseUtil sendJSEvent:self name:event body:message];
}
completionHandler(options);
}
// Handle notification messages after display notification is tapped by the user.
@ -129,10 +152,9 @@ didReceiveNotificationResponse:(UNNotificationResponse *)response
withCompletionHandler:(void(^)())completionHandler {
#endif
NSDictionary *message = [self parseUNNotification:response.notification messageType:@"NotificationResponse" openedFromTray:true];
[_callbackHandlers setObject:[completionHandler copy] forKey:message[@"messageId"]];
[RNFirebaseUtil sendJSEvent:self name:MESSAGING_MESSAGE_RECEIVED body:message];
[RNFirebaseUtil sendJSEvent:self name:NOTIFICATIONS_NOTIFICATION_CLICKED body:message];
completionHandler();
}
#endif