Frage

I'm trying to use NSUserNotificationCenter. I'm able to deliver notifications successfully. I'm using the ShouldPresentNotification callback on NSUserNotificationCenterDelegate to present notifications, even when the app is running in the foreground.

This works great, except on one of my machines!

I have stripped the code down to it's most basic example. All my machines are running 10.8.3 and Mono 2.10.12. On my 2008 Macbook Pro and a colleague's 2012 rMBP, everything works as excepted. However, on my identical 2012 rMBP the notification is not presented if the app is in the foreground. In fact, on this machine, and this machine only, none of the NSUserNotificationCenterDelegate methods are invoked.

Note that the notification is still delivered on this machine - the notification works - it just doesn't get presented when the app is in the foreground (because the delegate methods are never invoked).

I would really appreciate if anyone has some insight on what settings or configuration might causes this behaviour, or if there is some mechanism I can use to debug this behaviour.

Here is my code:

UNCShouldPresentNotification ShouldPresent = (a, b) => { return true; };

// Shared initialization code
void Initialize()
{
    NSUserNotificationCenter.DefaultUserNotificationCenter.ShouldPresentNotification = this.ShouldPresent;
}

partial void notify(NSObject sender)
{
    DoNotify();
}

[Export("doNotify")]
private void DoNotify()
{
    NSUserNotification notification = new NSUserNotification();
    notification.Title = notificationText.StringValue;

    NSUserNotificationCenter.DefaultUserNotificationCenter.DeliverNotification(notification);
}
War es hilfreich?

Lösung 2

This now works, somewhere between updating MonoMac, Mono and OS X on my machine.

Andere Tipps

Ok we had exactly the same bug. Firstly we contacted Xamarin and they've fixed it in the most recent code. Secondly it was due to overriding BOTH the Delegate delegate (great name I know) and the ShouldPresent setting. If you want to override the ShouldPresent setting, do this in your NSUserNotificationCenter.Delegate instead.

I hope that's clear. We've a resolved bugzille entry at https://bugzilla.xamarin.com/show_bug.cgi?id=11456

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top