Skip to content

[Bug] Can't get userData on iOS when user tapped on custom notification action #1035

Open
@nikita600

Description

@nikita600

[REQUIRED] Please fill in the following fields:

  • Pre-built SDK from the website or open-source from this repo: website
  • Firebase C++ SDK version: 7.0.2
  • Problematic Firebase Component: Messaging
  • Other Firebase Components in use: Analytics
  • Platform you are using the C++ SDK on: Unity
  • Platform you are targeting: iOS

[REQUIRED] Please describe the issue here:

Unity didn't get any message data if user tapped on custom notification action button if application was fully closed. I'm not quite sure is this issue valid on iOS 12.0 and lower, but potentially this issue happened on iOS 13.0 and higher. My device working on iOS 14.4

Steps to reproduce:

  1. Add NotificationExtensionsService to your Xcode project.
  2. Declare custom actions. UNNotificationAction should have options setted to UNNotificationActionOptions.
  3. Send notification payload with categoryIdentifier, that add custom action buttons in presented notification.
  4. Check if application fully closed.
  5. Tap on custom notification action button.
  6. When application was fully loaded you didn't get any message data.

Relevant Code:

As I understand, this issue happend just because on iOS 13.0 and higher, function application:didFinishLaunchingWithOptions: no longer gets launchOptions when user launches application from custom notification action button. So on iOS 13.0+ we never gets any message data on Unity side.

I'm not quite sure, but I see only one solution of this issue. Add else brach handling in firebase-cpp-sdk/messaging/src/ios/messaging.mm inside function:

- (void)userNotificationCenter:(UNUserNotificationCenter *)notificationCenter
didReceiveNotificationResponse:(UNNotificationResponse *)response
         withCompletionHandler:(void (^)())completionHandler {
  if (::firebase::messaging::MessagingIsInitialized()) {
    NSDictionary *userInfo = [[[[response notification] request] content] userInfo];
#if !defined(NDEBUG)
    ::firebase::LogInfo("FCM: userInfo: %s.", userInfo.description.UTF8String);
#endif
    ::firebase::messaging::g_message_notification_opened = true;
    ::firebase::messaging::NotifyApplicationAndServiceOfMessage(userInfo);
    id<UNUserNotificationCenterDelegate> user_delegate = ::firebase::messaging::g_user_delegate;
    [user_delegate userNotificationCenter:notificationCenter
           didReceiveNotificationResponse:response
                    withCompletionHandler:completionHandler];
  }
  else
  {
      if (@available(iOS 13.0, *))
      {
          ::firebase::messaging::g_launch_notification = userInfo;
      }
  }
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions