Xamarin.Mac UserNotificationExample: DidActivateNotification event is never fired

MuspetwonMuspetwon Mark MooreUSMember

Hi there,

I've downloaded Xamarin.Mac "UserNotificationExample" (sorry the forum doesn't allow me to post links, but you can easily google it by "UserNotificationExample xamarin.mac") and trying to make it work.

The app starts fine, and if I press "Notify Me Please!!" (i.e. schedule notification) then DidDeliverNotification is raised as expected.

NSUserNotificationCenter center = NSUserNotificationCenter.DefaultUserNotificationCenter;

center.DidDeliverNotification += (s, e) => 
{
    Console.WriteLine("Notification Delivered");
    DeliveredColorWell.Color = NSColor.Green;
};

center.DidActivateNotification += (s, e) => 
{
    Console.WriteLine("Notification Touched");
    TouchedColorWell.Color = NSColor.Green;
};

center.ShouldPresentNotification = (c, n) => { return true; };

center.ScheduleNotification(not);

and I can see "Notification Delivered" line in Application Output window.

But, if I click on notification window itself then DidActivateNotification is NOT raised, so "Notification Touched" is NOT written into Application Output window.

What I am doing wrong?

My system is:

OS X El Capitan 10.11.6

Visual Studio Community 2017 for Mac 7.1.5 (build 2)

Xamarin.Mac Version: 3.6.3.3 (Visual Studio Community)

Any help would be greatly appreciated.

Thanks

Tagged:

Answers

  • MuspetwonMuspetwon Mark Moore USMember
    edited September 27

    Thank you all for the replies.

    Just to make sure I understand you correctly:
    I want to catch the event when the user clicks somewhere inside the small notification window (the window which has bold "Hello World" and "This is an informative text") (sorry still not able to post screenshots here due to the forum restrictions) so my app can handle the click and perform some work.

    So if I understand you correctly if I click somewhere inside this window without Notification Center opened, then DidActivateNotification is not fired (screenshot is here snag.gy/COVIUr.jpg )

    Do I understand this correctly? It seems strange behavior (at least for Windows guy)...

    Edit:
    I've recorded a screencast on what is going on: goo.gl/i4Hq14

    As you see, first I click on "Notify Me Please!!" and then I am clicking on the small notification window, but DidActivateNotification is not fired, so Notification Touched box is always red.

  • ChrisHamonsChrisHamons Chris Hamons USXamarin Team Xamurai

    DidActivateNotification is a terrible name for the API you are invoking. UserNotificationCenterActivateNotification is a better one (it's "userNotificationCenter:didActivateNotification"). Thus, if you are clicking on notifications it fires, but does not generally fire for window activation.

    If you want general window activation notifications, use the INSWindowDelegate API i showed above.

  • ChrisHamonsChrisHamons Chris Hamons USXamarin Team Xamurai

    It is unlikely we'll be able to fix the names in any reasonable timeframe (API compatibility) but I filed a bug here for tracking: https://bugzilla.xamarin.com/show_bug.cgi?id=59792

  • JGoldbergerJGoldberger Jon Goldberger USXamarin Team, University Xamurai
    edited October 17

    @Muspetwon said:
    Thank you all for the replies.

    Just to make sure I understand you correctly:
    I want to catch the event when the user clicks somewhere inside the small notification window (the window which has bold "Hello World" and "This is an informative text") (sorry still not able to post screenshots here due to the forum restrictions) so my app can handle the click and perform some work.

    So if I understand you correctly if I click somewhere inside this window without Notification Center opened, then DidActivateNotification is not fired (screenshot is here snag.gy/COVIUr.jpg )

    Do I understand this correctly? It seems strange behavior (at least for Windows guy)...

    On my end, if I clicked in the notification "window," even without the notification center open, the DidActivateNotification event was fired. However it is not fired if I swipe the notification to the right to dismiss it.

    You accepted my answer so I assume that means you have it working now. :-)

    EDIT: As indicated later, the answer was accepted erroneously. I have unmarked those answers as accepted answers.

  • MuspetwonMuspetwon Mark Moore USMember

    Thanks Chris and Joh, your help much appreciated.

    I'm new to the forum and though that "Did this answer the question? Yes" is something like "Like" so I accepted the first two replies mistakenly and can't undo the action, sorry about that.

    On my end, if I clicked in the notification "window," even without the notification center open, the DidActivateNotification event was fired.

    It is exactly opposite of what I see on my end. When I clicked in the notification "window" without notification center open, DidActivateNotification event was not fired: goo.gl/i4Hq14
    But if I click in the notification windows when notification center open, DidActivateNotification event was fired successfully: goo.gl/tvAocq

    I will make the same test on other Mac a bit later and let you know about the results (I tend to think something is wrong with my setup...).

  • JGoldbergerJGoldberger Jon Goldberger USXamarin Team, University Xamurai

    Could be a difference between El Capitan and Sierra versions of macOS?

  • MuspetwonMuspetwon Mark Moore USMember
    edited October 5

    Sorry for the delay in response.

    Here are the results of my tests on other Macs.
    I've tried the example on Sierra and everything worked as expected, i.e. DidActivateNotification event was fired when I clicked on the notification (video: goo.gl/xAy7BN).
    I've tried the example on other El Capitan and it also doesn't work.

    So, to sum up.
    It seems the event is not delivered on El Capitan: goo.gl/i4Hq14
    But it works on Sierra: goo.gl/xAy7BN

    Personally I could live with it. But does somebody have any idea on what is the reason of the behavior?

  • ChrisHamonsChrisHamons Chris Hamons USXamarin Team Xamurai

    Apple has changed API behaviors between macOS versions, and even between the same version when linking against different SDKs. This does not surprise me.

Sign In or Register to comment.