quickstart-unity icon indicating copy to clipboard operation
quickstart-unity copied to clipboard

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

Open nikita600 opened this issue 4 years ago • 8 comments

[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;
      }
  }
}

nikita600 avatar Mar 14 '21 21:03 nikita600

To confirm: does this else branch functionally fix the issue for you?

patm1987 avatar Mar 25 '21 21:03 patm1987

Hey @nikita600. We need more information to resolve this issue but there hasn't been an update in 5 weekdays. I'm marking the issue as stale and if there are no new updates in the next 5 days I will close it automatically.

If you have more information that will help us get to the bottom of this, just add a comment!

google-oss-bot avatar Apr 01 '21 01:04 google-oss-bot

Sorry, I completely forgot to answer in this thread. I still can't check this issue on my environment, but I try to check this issue on this week.

nikita600 avatar Apr 01 '21 05:04 nikita600

Hey @nikita600. We need more information to resolve this issue but there hasn't been an update in 5 weekdays. I'm marking the issue as stale and if there are no new updates in the next 5 days I will close it automatically.

If you have more information that will help us get to the bottom of this, just add a comment!

google-oss-bot avatar Apr 08 '21 01:04 google-oss-bot

I finally try to compile sources of this library with potential fix. I import compiled library into the Unity project, generated Xcode project and gets a lot of errors that looks like: "Undefined symbols SWIGRegisterStringCallback_FirebaseMessaging". And then I realize that I can't test this fix by myself, because this repository doesn't contains any Unity code.

What I can do in this case?

nikita600 avatar Apr 11 '21 13:04 nikita600

One way to test it would be to build the C++ library on its own. Then install the Firebase Unity package as normal and locate the C++ library that's bundled with it. Swap out the bundled library with your custom built one, and that should work and hopefully unblock you.

In the mean time I'll schedule some time to look at this so we can test it out your fix ourselves and get it merged in.

alexames avatar Apr 13 '21 08:04 alexames

@nikita600 I think you mentioned Unity in your first post.

Let me move this to quickstart-unity for management purpose, even though this may be issue in C++ level.

chkuang-g avatar Apr 23 '21 17:04 chkuang-g

Hey folks,

I did an experiment awhile ago and did notice some different behavior between Firebase Unity SDK and Firebase iOS SDK when NotificationExtensionsService is in use.

The internal bug to track this:

b/182008240

While the issue you reported is when the app is fully closed, the inconsistent behavior I found was when the app is in foreground though. But I suspect that is related to the issue you reported

SDK/Sample Foreground Behavior Background Behavior
iOS Advanced Sample Notification in system tray Notification in system tray
Unity quickstart with modification OnMessageReceived, no notification in system tray Notification in system tray

I will mark it as a bug for further investigation.

chkuang-g avatar Apr 23 '21 18:04 chkuang-g