Bug 11456 - NSUserNotifications no longer displaying, regardless of ShouldPresentNotification delegate – worked in Xam.Mac < 1.2
Summary: NSUserNotifications no longer displaying, regardless of ShouldPresentNotifica...
Status: RESOLVED FIXED
Alias: None
Product: Xamarin.Mac
Classification: Desktop
Component: Library (Xamarin.Mac.dll) ()
Version: 1.2.x
Hardware: PC Mac OS
: Normal normal
Target Milestone: ---
Assignee: Aaron Bockover [MSFT]
URL:
Depends on:
Blocks:
 
Reported: 2013-03-28 04:28 UTC by ian
Modified: 2013-05-29 10:57 UTC (History)
3 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FIXED

Description ian 2013-03-28 04:28:51 UTC
NSUserNotifications no longer displaying, regardless of ShouldPresentNotification delegate – worked in Xam.Mac < 1.2

A new issue and very urgent : we rely heavily on user notifications and the new notification are in OSX 10.8

-	In Xam.Mac 1.0/1.1  every notification that was sent would ‘pop’, or display, as we followed the documentation (and sample) and always set the delegate:
o	center.ShouldPresentNotification = (c, n) => { return true; };

However, as per this forum entry http://forums.xamarin.com/discussion/2675/nsusernotificationcenter-shouldpresentnotification-broken-sample , we also no longer have the same behaviour.

We've added a log entry to the delegate, this shows it is now NEVER called.

This is urgent, please advise as currently notifications rarely show.

thanks ian
Comment 1 Aaron Bockover [MSFT] 2013-03-28 10:58:58 UTC
I'm not experiencing any issues with the API. I see the notifications as bubbles and in the notification center.

public override void AwakeFromNib ()
{
	base.AwakeFromNib ();

	var notifCenter = NSUserNotificationCenter.DefaultUserNotificationCenter;

	notifCenter.ShouldPresentNotification = (c, n) => true;

	NotificationButton.Activated += (o, e) => {
		notifCenter.ScheduleNotification (new NSUserNotification {
			Title = "Test from main thread"
		});

		NSThread.Start (() => notifCenter.ScheduleNotification (new NSUserNotification {
			Title = "Test from background thread"
		}));
	};
}
Comment 2 Aaron Bockover [MSFT] 2013-03-28 10:59:29 UTC
Can you provide a fully self contained test case we can debug?
Comment 3 Aaron Bockover [MSFT] 2013-03-28 11:02:49 UTC
The UserNotificationExample project works as expected with no code changes. Are you sure you haven't changed your system notification preferences somehow?
Comment 4 ian 2013-04-02 11:32:47 UTC
We find it's unpredictable, as does the person who raised this originally.
Is there no one who finds it a problem at Xamarin?
Comment 5 Miguel de Icaza [MSFT] 2013-04-02 11:35:59 UTC
There are just enough reasons to believe that this could be either a user configuration setting, or a misuse of the API.  

There is no indication that this is caused by a bug in the binding, or the compilers.  So pending a self-contained test case that we can dissect, chances are, this is not a bug in the product.
Comment 6 ian 2013-04-02 11:38:30 UTC
Hi Miguel,
I am trying to generate test cases for the couple of issues we have. 
There is certainly a problem with notifications 'popping' - there's other users with the same issue.
I completely understand I need to generate an example so you can trace it, but any app that sends 10 notifications within a minute that may or may not be the key app will have the issue.

I'll attempt to create the example.
Comment 7 ian 2013-04-08 03:56:06 UTC
Hi Miguel / Aaron,

We've found the root cause - the samples are a little primitive for a full understanding I think.

We have a component that sends notifications. We setup the delegate for the notification at the start of our app (as it never changes). The problem is that if there is no reference kept to the notification centre, once the delegate is set, then once the notification centre reference is GCed the delegate is also GCed.

This means any override of the default notification behaviour, eg. always returning tru to ensure the notification is displayed, is lost.

We've fixed it by keeping a static variable for the lifetime of the app. Works everytime now.

Cheers
ian
Comment 8 Miguel de Icaza [MSFT] 2013-04-08 12:28:33 UTC
Which variable did you keep a reference to?

We are internally keeping a reference to the NSUserNotificationCenter.DefaultUserNotificationCenter so you should not need to.

Unless you are using your own NSUserNotificationCenter, is that ht ecase?
Comment 9 Francesco P 2013-04-09 08:17:49 UTC
Hi Miguel, I work with Ian and we identified the actual real problem to have nothing to do with GC.

The problem is that we can set both the ShouldPresentNotifications and Delegate properties on the NSUserNotificationCenter object.

What we discovered is that this properties are mutually exclusive, in that setting the Delegate "overrides" the current one set previously using ShouldPresentNotifications. And viceversa.

We now only set the Delegate property and in our delegate we override ShouldPresentNotifications, which is not set directly via the NSUserNotificationCenter anymore.

Hope this removes the confusion that other people might have experienced as well.
Comment 10 Miguel de Icaza [MSFT] 2013-04-09 09:54:05 UTC
Thank you for the feedback.
Comment 11 Nischal 2013-05-29 10:12:41 UTC
To verify this issue we have checked Mac Sample "UserNotificationSample" and this application working fine. Please let us know is this correct sample which we have checked for this sample.
Comment 12 Nischal 2013-05-29 10:57:38 UTC
An update to the Comment#11:

This is the build info which we have used for this issue:

Xamarin.Mac 1.4.0
Mono 2.10.12
X.S 4.0.8(build 2)