Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Firebase integration disables CurrentNotificationActionTapped trigger #451

Open
Bindslev opened this issue Sep 28, 2023 · 4 comments
Open
Assignees
Labels
bug Something isn't working iOS iOS only issue

Comments

@Bindslev
Copy link

Describe the bug
Most likely a configuration issue, but when I use local notifications together with push notifications from firebase (this plugin https://github.com/TobiasBuchholz/Plugin.Firebase), the notifications I get from this plugin doesn't respond to clicks.

So, I actually do receive both notifications as I should, but my local notification contains action buttons, and when I have push notifications enabled, the CurrentNotificationActionTapped won't trigger when clicking the action buttons.

I have added this piece of code from the documentation regarding push notifications:

.AddiOS(iOS =>
            {
#if IOS
                iOS.SetCustomUserNotificationCenterDelegate(new CustomUserNotificationCenterDelegate());
#endif
            });

and my CustomUserNotificationCenterDelegate class looks identical to the one in the documentation.

In my dependency injection setup, I'm not sure whether to register this plugin, or firebase first, and they act very differently depending on what I register first;

If I register this plugin first, I'll get both local notifications and push notifications, but CurrentNotificationActionTapped is not triggered on the local notification when the action buttons are clicked.
If I register the firebase plugin first, I'll only get local notifications and CurrentNotificationActionTapped is triggered just fine, but push notifications won't appear at all.

Any guidance would be much appreciated. Everything works just fine in isolation.

To Reproduce
Steps to reproduce the behavior:
Install firebase cloud messaging in an app with this plugin and add action buttons to the local notification. Now CurrentNotificationActionTapped won't trigger if clicked.

Expected behavior
I would expect that the CurrentNotificationActionTapped is triggered AND that I can also retrieve push notifications. - Again, both of those work in isolation but not when both are enabled.

Screenshots
If applicable, add screenshots to help explain your problem.

Platform (please complete the following information):

  • OS: iOS
  • Version 16 & 17

Smartphone (please complete the following information):

  • Device: iPhone 15 Pro, iPhone 7, iPhone X, iPhone 14 (simulator)
  • OS: iOS
  • Version 16 & 17
@Bindslev Bindslev added the bug Something isn't working label Sep 28, 2023
@thudugala
Copy link
Owner

@Bindslev Can you please attach a sample project?

@thudugala thudugala added the iOS iOS only issue label Sep 29, 2023
@borrmann
Copy link

borrmann commented Nov 14, 2023

I actually have a similar, but kind of opposite problem (using apns, though).
Previously I handled taps on my push notifications in AppDelegate

public override bool FinishedLaunching(UIApplication app, NSDictionary options)
{
    if (DeviceInstallationService.NotificationsSupported)
    {
        UNUserNotificationCenter.Current.RequestAuthorization(
                UNAuthorizationOptions.Alert |
                UNAuthorizationOptions.Badge |
                UNAuthorizationOptions.Sound,
                (approvalGranted, error) =>
                {
                    if (approvalGranted && error == null)
                        RegisterForRemoteNotifications();
                });
    }
    using (var userInfo = options?.ObjectForKey(UIApplication.LaunchOptionsRemoteNotificationKey) as NSDictionary) ProcessNotificationActions(userInfo);


    UNUserNotificationCenter.Current.Delegate = new UserNotificationCenterDelegate();

    return base.FinishedLaunching(app, options);
}
void ProcessNotificationActions(NSDictionary userInfo)
{
    if (userInfo == null)
        return;

    try
    {
        var actionValue = userInfo.ObjectForKey(new NSString("action")) as NSString;

        if (!string.IsNullOrWhiteSpace(actionValue?.Description))
            NotificationActionService.TriggerAction(actionValue.Description);
    }
    catch (Exception ex)
    {
        Debug.WriteLine(ex.Message);
    }
}

but this doesnt work anymore. I figured I now have to use the mentioned CustomUserNotificationCenterDelegate, but I don't know how to get my previously used var actionValue = userInfo.ObjectForKey(new NSString("action")) as NSString; as I have no clue about all those iOS objects. I suppose it is probably somewhere inside UNNotificationResponse response?

@borrmann
Copy link

Also I can confirm it is not a problem with DidReceiveNotificationResponse inside CustomUserNotificationCenterDelegate. It does get triggered when I tap a Push-Notification, but it doesnt seem to have the information of the tapped notification like I was able before. (OR - I dont know where to find it)

I tried this:

Console.WriteLine(response.Notification.ToString());

but what I get is this:

<UNNotification: 0x283dd77b0; source: <<mypackagename>> date: 2023-11-14 16:16:31 +0000, request: <UNNotificationRequest: 0x283dd4ed0; identifier: 1BB89C3B-2390-4DAF-8760-2318B44EB3B7, content: <UNNotificationContent: 0x151604e70; title: (null), subtitle: (null), body: <redacted>, summaryArgument: , summaryArgumentCount: 0, categoryIdentifier: , launchImageName: , threadIdentifier: , attachments: (
2023-11-14 16:16:32.627 <<myNamespaceRemoved>>[12077:9575350] ), badge: (null), sound: (null), realert: 0, interruptionLevel: 1, relevanceScore: 0.00, filterCriteria: (null), screenCaptureProhibited: 0, trigger: <UNPushNotificationTrigger: 0x28b1ef540; contentAvailable: NO, mutableContent: NO>>, intents: (
)>

although the notification that was tapped did have a title and description. Again, I assume the data is probably somewhere but I have no clue about the iOS objects and am struggling to find the information I need.

Any help would be much appreciated!

@borrmann
Copy link

I figured it out with the help of this this
that my data was hiding just here!

var actionValue = response.Notification.Request.Content.UserInfo.ObjectForKey(new NSString("action"));
if(!string.IsNullOrWhiteSpace(actionValue?.Description))
    MyPushNotificationHandler(actionValue.Description);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working iOS iOS only issue
Projects
None yet
Development

No branches or pull requests

3 participants