public static void PopNotificationToUrl(string title, string text, string url, string readUrl) { // First we create our notification and customize as needed NSUserNotification not = new NSUserNotification(); not.Title = title; not.InformativeText = text; not.DeliveryDate = DateTime.Now; not.SoundName = NSUserNotification.NSUserNotificationDefaultSoundName; not.SetValueForKey (new NSString (url), new NSString("htmlUrl")); not.SetValueForKey (new NSString (readUrl), new NSString("readUrl")); // We get the Default notification Center NSUserNotificationCenter center = NSUserNotificationCenter.DefaultUserNotificationCenter; center.DidActivateNotification += (s, e) => { // This removes the notification from the notification center center.RemoveDeliveredNotification(e.Notification); // This opens a website URL NSWorkspace.SharedWorkspace.OpenUrl(new NSUrl(e.Notification.ValueForKey(new NSString("htmlUrl")).ToString())); // This marks it as read _api.MarkThreadRead(e.Notification.ValueForKey(new NSString("readUrl")).ToString()); }; // If we return true here, Notification will show up even if your app is TopMost. center.ShouldPresentNotification = (c, n) => { return true; }; center.ScheduleNotification(not); }
public static void PopNotificationToUrl(string title, string text, string url, string readUrl) { // First we create our notification and customize as needed NSUserNotification not = new NSUserNotification(); not.Title = title; not.InformativeText = text; not.DeliveryDate = DateTime.Now; not.SoundName = NSUserNotification.NSUserNotificationDefaultSoundName; not.SetValueForKey(new NSString(url), new NSString("htmlUrl")); not.SetValueForKey(new NSString(readUrl), new NSString("readUrl")); // We get the Default notification Center NSUserNotificationCenter center = NSUserNotificationCenter.DefaultUserNotificationCenter; center.DidActivateNotification += (s, e) => { // This removes the notification from the notification center center.RemoveDeliveredNotification(e.Notification); // This opens a website URL NSWorkspace.SharedWorkspace.OpenUrl(new NSUrl(e.Notification.ValueForKey(new NSString("htmlUrl")).ToString())); // This marks it as read _api.MarkThreadRead(e.Notification.ValueForKey(new NSString("readUrl")).ToString()); }; // If we return true here, Notification will show up even if your app is TopMost. center.ShouldPresentNotification = (c, n) => { return(true); }; center.ScheduleNotification(not); }
public NSUserNotification CreateNotification(Song song) { var notification = new NSUserNotification { Title = song.Name, Subtitle = song.Album, InformativeText = song.Artist, HasActionButton = true, ActionButtonTitle = "Skip", }; //todo: get artwork //notification.ContentImage SetImage(notification, song); //notification.contentImage = [self albumArtForTrack: currentTrack]; //Private APIs – remove if publishing to Mac App Store try { notification.SetValueForKey(NSObject.FromObject(true), (NSString)"_showsButtons"); // Show album art on the left side of the notification (where app icon normally is), //like iTunes does //[notification setValue:notification.contentImage forKey:@"_identityImage"]; //notification.contentImage = nil; } catch (Exception ex) { Console.WriteLine(ex); } return(notification); }
async void SetImage(NSUserNotification notification, Song song) { try { var imageTask = GetImage(song, 50); if (imageTask.IsCompleted) { notification.ContentImage = imageTask.Result; } else { notification.ContentImage = await imageTask; } if (notification.ContentImage == null) { return; } notification.SetValueForKey(notification.ContentImage, (NSString)"_identityImage"); notification.ContentImage = null; } catch (Exception ex) { Console.WriteLine(ex); } }