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); } }
/// <summary> /// Creates a scheduled toast notification with the required values. /// </summary> /// <param name="content">Text content.</param> /// <param name="title">Toast title.</param> /// <param name="deliveryTime">When to display the toast.</param> /// <returns></returns> public static ScheduledToastNotification CreateScheduledToastNotification(string content, string title, DateTimeOffset deliveryTime) { #if WINDOWS_UWP || WINDOWS_APP || WINDOWS_PHONE_APP || WINDOWS_PHONE_81 XmlDocument doc = Windows.UI.Notifications.ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastText02); var textElements = doc.GetElementsByTagName("text"); textElements[0].InnerText = title; textElements[1].InnerText = content; return(new ScheduledToastNotification(new Windows.UI.Notifications.ScheduledToastNotification(doc, deliveryTime))); #elif WINDOWS_PHONE throw new PlatformNotSupportedException(); #elif __ANDROID__ throw new PlatformNotSupportedException(); #elif __MAC__ NSUserNotification notification = new NSUserNotification(); notification.Title = title; notification.InformativeText = content; notification.SoundName = NSUserNotification.NSUserNotificationDefaultSoundName; notification.DeliveryDate = deliveryTime.ToNSDate(); return(notification); #elif __UNIFIED__ UNMutableNotificationContent notificationContent = new UNMutableNotificationContent(); notificationContent.Title = title; notificationContent.Body = content; notificationContent.Sound = UNNotificationSound.Default; NSDateComponents dc = NSCalendar.CurrentCalendar.Components(NSCalendarUnit.Year | NSCalendarUnit.Month | NSCalendarUnit.Day | NSCalendarUnit.Hour | NSCalendarUnit.Minute | NSCalendarUnit.Second, deliveryTime.ToNSDate()); UNCalendarNotificationTrigger trigger = UNCalendarNotificationTrigger.CreateTrigger(dc, false); return(new ScheduledToastNotification(notificationContent, trigger)); #else return(new ScheduledToastNotification(content, title, deliveryTime)); #endif }
private void sendNotification(string title, string text, string url) { // 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; // We get the Default notification Center NSUserNotificationCenter center = NSUserNotificationCenter.DefaultUserNotificationCenter; /*center.DidDeliverNotification += (s, e) => { Console.WriteLine("Notification Delivered"); DeliveredColorWell.Color = NSColor.Green; };*/ center.DidActivateNotification += (s, e) => { // This removes the notification from the notification center center.RemoveDeliveredNotification(e.Notification); Console.WriteLine("Opening " + url); // This opens a website URL NSWorkspace.SharedWorkspace.OpenUrl(new NSUrl(url)); }; // If we return true here, Notification will show up even if your app is TopMost. center.ShouldPresentNotification = (c, n) => { return true; }; center.ScheduleNotification(not); }
partial void NotifyMeAction(MonoMac.AppKit.NSButton sender) { // First we create our notification and customize as needed NSUserNotification not = new NSUserNotification(); not.Title = "Hello World"; not.InformativeText = "This is an informative text"; not.DeliveryDate = DateTime.Now; not.SoundName = NSUserNotification.NSUserNotificationDefaultSoundName; // We get the Default notification Center 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; }; // If we return true here, Notification will show up even if your app is TopMost. center.ShouldPresentNotification = (c, n) => { return(true); }; center.ScheduleNotification(not); }
private void TimerEnd() { _timer.Stop(); WriteDataToArduino(ArduinoCommands.Down); InvokeOnMainThread(() => { _stopItem.Enabled = false; _statusItem.Title = string.Empty; SetSystemIcon(); UncheckMenuItems(); }); if (!_manualStopRequested) { //Trigger a local notification after the time has elapsed var notification = new NSUserNotification(); notification.Title = "OH NO! RUN! HIDE!"; notification.InformativeText = $"{_timerDuration} minutes are up!"; notification.SoundName = NSUserNotification.NSUserNotificationDefaultSoundName; NSUserNotificationCenter.DefaultUserNotificationCenter.DeliverNotification(notification); } _manualStopRequested = false; }
public SparkleBubbles() { Controller.ShowBubbleEvent += delegate (string title, string subtext, string image_path) { // Notification center was introduced in Mountain Lion if (Environment.OSVersion.Version.Major < 12) return; InvokeOnMainThread (delegate { NSUserNotification notification = new NSUserNotification () { Title = title, InformativeText = subtext, DeliveryDate = DateTime.Now }; NSUserNotificationCenter center = NSUserNotificationCenter.DefaultUserNotificationCenter; center.ShouldPresentNotification = delegate { return true; }; center.DidActivateNotification += delegate { Controller.BubbleClicked (); }; center.ScheduleNotification (notification); }); }; }
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 async Task <NotificationFeedback> Show(Notification notification) { var guid = Guid.NewGuid(); var not = new NSUserNotification { Title = notification.Title, InformativeText = notification.Description, DeliveryDate = NSDate.Now, SoundName = NSUserNotification.NSUserNotificationDefaultSoundName, ActionButtonTitle = notification.PrimaryAction.Or(""), HasActionButton = notification.PrimaryAction.HasValue, UserInfo = NSDictionary.FromObjectAndKey(new NSString(guid.ToString()), Key), }; // Approach described by http://stackoverflow.com/questions/21110714/mac-os-x-nsusernotificationcenter-notification-get-dismiss-event-callback/21365269#21365269 var dismissed = _currentNotifications .SkipWhile(s => !s.Contains(guid)) .SkipWhile(s => s.Contains(guid)) .Take(1); var activated = _notificationActivated .Where(n => n.Equals(guid)); var status = Observable.Merge( dismissed.Select(_ => NotificationFeedback.Dismissed), activated.Select(_ => NotificationFeedback.PrimaryActionTaken)); var task = status.FirstAsync().ToTask(); await MainThread.BeginInvoke(() => _center.DeliverNotification(not)); return(await task); }
/// <summary> /// Shows a native Mac OS notification. /// </summary> public async Task Show() { // The deprecated NSUserNotification is the only one available on // Xamarin.Mac var notification = new NSUserNotification { Title = Title, InformativeText = Message }; if (AppLogoOverride != null) { // Just get stream for all cases, handling the ms-appx:// stuff is tricky. var str = await AppLogoOverride.GetDataUrlAsync().ConfigureAwait(false); int i = "data:;base64,".Length; str = str.Substring(i); var data = new NSData(str, NSDataBase64DecodingOptions.None); notification.ContentImage = new AppKit.NSImage(data); } var center = NSUserNotificationCenter.DefaultUserNotificationCenter; center.DeliverNotification(notification); }
protected override void NotifyUser(string title, string message, NotificationType type) { var notification = new NSUserNotification(); notification.Title = title; notification.InformativeText = message; notification.DeliveryDate = DateTime.Now; notification.SoundName = NSUserNotification.NSUserNotificationDefaultSoundName; // We get the Default notification Center var center = NSUserNotificationCenter.DefaultUserNotificationCenter; // TODO: Figure out why this does not work if (center == null) { return; } //center.DidDeliverNotification += (s, e) => { }; center.DidActivateNotification += (s, e) => { }; // If we return true here, Notification will show up even if your app is TopMost. center.ShouldPresentNotification = (c, n) => { return(true); }; center.ScheduleNotification(notification); }
public SparkleBubbles() { Controller.ShowBubbleEvent += delegate(string title, string subtext, string image_path) { // Notification center was introduced in Mountain Lion if (Environment.OSVersion.Version.Major < 12) { return; } InvokeOnMainThread(delegate { NSUserNotification notification = new NSUserNotification() { Title = title, InformativeText = subtext, DeliveryDate = DateTime.Now }; NSUserNotificationCenter center = NSUserNotificationCenter.DefaultUserNotificationCenter; center.ShouldPresentNotification = delegate { return(true); }; center.DidActivateNotification += delegate { Controller.BubbleClicked(); }; center.ScheduleNotification(notification); }); }; }
public void Notification(string title, string notes) { RequestAttention(); if (Engine.Instance.Storage.GetBool("gui.osx.notifications") == false) { return; } // First we create our notification and customize as needed NSUserNotification not = null; try { not = new NSUserNotification(); } catch { // This API was introduced in OS X Mountain Lion (10.8) return; } not.Title = title; not.InformativeText = notes; not.DeliveryDate = NSDate.Now; not.SoundName = NSUserNotification.NSUserNotificationDefaultSoundName; // We get the Default notification Center NSUserNotificationCenter center = NSUserNotificationCenter.DefaultUserNotificationCenter; // 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); }
public void Notify(Shared.Services.Notification.INotification notification) { // Trigger a local notification after the time has elapsed var sysNotification = new NSUserNotification(); // Add text and sound to the notification sysNotification.Title = notification.GetTitle(); sysNotification.InformativeText = notification.GetMessage(); sysNotification.SoundName = NSUserNotification.NSUserNotificationDefaultSoundName; sysNotification.HasActionButton = true; sysNotification.HasReplyButton = false; if (notification.GetParameters().Count > 0) { List <string> keys = new List <string>(); List <string> values = new List <string>(); foreach (KeyValuePair <string, string> item in notification.GetParameters()) { keys.Add(item.Key); values.Add(item.Value); } sysNotification.UserInfo = NSDictionary.FromObjectsAndKeys(values.ToArray(), keys.ToArray()); } Notify(sysNotification); }
public void Notify(NSUserNotification notification) { NotificationCenter.DeliverNotification(notification); //ActiveNotifications.Add(notification); //UpdateBadge(); }
partial void NotifyMeAction (MonoMac.AppKit.NSButton sender) { // First we create our notification and customize as needed NSUserNotification not = new NSUserNotification(); not.Title = "Hello World"; not.InformativeText = "This is an informative text"; not.DeliveryDate = DateTime.Now; not.SoundName = NSUserNotification.NSUserNotificationDefaultSoundName; // We get the Default notification Center 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; }; // If we return true here, Notification will show up even if your app is TopMost. center.ShouldPresentNotification = (c, n) => { return true; }; center.ScheduleNotification(not); }
/// <summary> /// Creates a toast notification with the required values. /// </summary> /// <param name="content">Text content.</param> /// <param name="title">Toast title.</param> /// <returns></returns> public static ToastNotification CreateToastNotification(string content, string title) { #if WINDOWS_UWP || WINDOWS_APP || WINDOWS_PHONE_APP || WINDOWS_PHONE_81 XmlDocument doc = Windows.UI.Notifications.ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastText02); var textElements = doc.GetElementsByTagName("text"); textElements[0].InnerText = title; textElements[1].InnerText = content; return(new Windows.UI.Notifications.ToastNotification(doc)); #elif WINDOWS_PHONE return(new ToastNotification(new Microsoft.Phone.Shell.ShellToast() { Title = title, Content = content })); #elif __ANDROID__ return(Toast.MakeText(Plugin.CurrentActivity.CrossCurrentActivity.Current.Activity, title + "\r\n" + content, ToastLength.Long)); #elif __MAC__ NSUserNotification notification = new NSUserNotification(); notification.Title = title; notification.InformativeText = content; notification.SoundName = NSUserNotification.NSUserNotificationDefaultSoundName; return(notification); #elif __UNIFIED__ UNMutableNotificationContent notificationContent = new UNMutableNotificationContent(); notificationContent.Title = title; notificationContent.Body = content; notificationContent.Sound = UNNotificationSound.Default; return(new ToastNotification(notificationContent)); #else return(new ToastNotification(content, title)); #endif }
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); }
private void sendNotification(string title, string text, string url) { // 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; // We get the Default notification Center NSUserNotificationCenter center = NSUserNotificationCenter.DefaultUserNotificationCenter; /*center.DidDeliverNotification += (s, e) => * { * Console.WriteLine("Notification Delivered"); * DeliveredColorWell.Color = NSColor.Green; * };*/ center.DidActivateNotification += (s, e) => { // This removes the notification from the notification center center.RemoveDeliveredNotification(e.Notification); Console.WriteLine("Opening " + url); // This opens a website URL NSWorkspace.SharedWorkspace.OpenUrl(new NSUrl(url)); }; // 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 override Task Send(Notification notification) => this.Invoke(() => { if (notification.Id == null) { notification.GeneratedNotificationId(); } // untested if (string.IsNullOrEmpty(notification.Sound)) { if (!string.IsNullOrEmpty(Notification.DefaultSound)) { notification.Sound = Notification.DefaultSound; } else if (Notification.SystemSoundFallback) { notification.Sound = NSUserNotification.NSUserNotificationDefaultSoundName; } } var native = new NSUserNotification { Identifier = notification.Id.Value.ToString(), Title = notification.Title, InformativeText = notification.Message, SoundName = notification.Sound, DeliveryDate = notification.SendTime.ToNSDate(), UserInfo = notification.Metadata.ToNsDictionary() }; NSUserNotificationCenter .DefaultUserNotificationCenter .ScheduleNotification(native); });
public bool IsNotificationTransmission(NSUserNotification notification) { if (null != notification.UserInfo && notification.UserInfo.ContainsKey((NSString)notificationType)) { return(notificationTypeTransmission == (string)(notification.UserInfo [notificationType] as NSString)); } return(false); }
private bool IsNotificationCredentials(NSUserNotification notification) { if (null != notification.UserInfo && notification.UserInfo.ContainsKey((NSString)notificationType)) { return(notificationTypeCredentials == (string)(notification.UserInfo [notificationType] as NSString)); } return(false); }
private bool IsNotificationAWarning(NSUserNotification notification) { if (null != notification.UserInfo && notification.UserInfo.ContainsKey((NSString)notificationType)) { return(notificationTypeAlert == (string)(notification.UserInfo[notificationType] as NSString)); } return(false); }
void ShowNotificationWithNSUserNotifications(string title, string text) { var notification = new NSUserNotification(); notification.Title = title; notification.InformativeText = text; NSUserNotificationCenter.DefaultUserNotificationCenter.DeliverNotification(notification); }
/// <summary> /// Show a local notification at a specified time /// </summary> /// <param name="title">Title of the notification</param> /// <param name="body">Body or description of the notification</param> /// <param name="id">Id of the notification</param> /// <param name="notifyTime">Time to show notification</param> public void Show(string title, string body, int id, DateTime notifyTime) { var notification = new NSUserNotification() { Title = title, InformativeText = body, Identifier = id.ToString(), DeliveryDate = (NSDate)notifyTime }; NSUserNotificationCenter.DefaultUserNotificationCenter.ScheduleNotification(notification); }
internal static void DidActivateNotification(NSUserNotification notification) { NSObject idString, dataString; if (notification.UserInfo.TryGetValue(NotificationHandler.Info_Id, out idString)) { notification.UserInfo.TryGetValue(NotificationHandler.Info_Data, out dataString); var app = ApplicationHandler.Instance; app.Callback.OnNotificationActivated(app.Widget, new NotificationEventArgs((NSString)idString, dataString as NSString)); NSUserNotificationCenter.DefaultUserNotificationCenter.RemoveDeliveredNotification(notification); } }
public void ShowNotification(string title, string message) { var center = NSUserNotificationCenter.DefaultUserNotificationCenter; var notification = new NSUserNotification() { Title = title, InformativeText = message, DeliveryDate = NSDate.Now }; center.ScheduleNotification(notification); }
public bool DisplayNotification(string identifier, string title, string text) { using (var notification = new NSUserNotification { Identifier = identifier, Title = title, InformativeText = text, SoundName = NSUserNotification.NSUserNotificationDefaultSoundName }) NSUserNotificationCenter.DefaultUserNotificationCenter.DeliverNotification(notification); return(true); }
/// <summary> /// Notifies the user. /// </summary> /// <typeparam name="T">The source type.</typeparam> /// <param name="sender">The sender.</param> /// <param name="title">The title.</param> /// <param name="informativeText">The informative text.</param> /// <returns>The source observable.</returns> public static IObservable <T> NotifyUser <T>(this IObservable <T> sender, string title, string informativeText) { var notification = new NSUserNotification { Title = title, InformativeText = informativeText, DeliveryDate = (NSDate)DateTime.Now, SoundName = NSUserNotification.NSUserNotificationDefaultSoundName, HasActionButton = true }; UserNotificationCenter.ScheduleNotification(notification); return(sender); }
public void Notify(string title, string description) { // Trigger a local notification after the time has elapsed var notification = new NSUserNotification(); // Add text and sound to the notification notification.Title = title; notification.InformativeText = description; notification.SoundName = NSUserNotification.NSUserNotificationDefaultSoundName; notification.HasActionButton = false; notification.HasReplyButton = false; Notify(notification); }
public void Show(string title, string message) { // Trigger a local notification after the time has elapsed var notification = new NSUserNotification { // Add text and sound to the notification Title = title, InformativeText = message, SoundName = NSUserNotification.NSUserNotificationDefaultSoundName, HasActionButton = false }; NSUserNotificationCenter.DefaultUserNotificationCenter.DeliverNotification(notification); }
private void ShowBubbleEvent (string title, string subtext, string image_path) { InvokeOnMainThread (() => { NSUserNotification notification = new NSUserNotification () { Title = title, InformativeText = subtext, DeliveryDate = DateTime.Now }; NSUserNotificationCenter center = NSUserNotificationCenter.DefaultUserNotificationCenter; center.ShouldPresentNotification = delegate { return true; }; center.DidActivateNotification += delegate { Controller.BubbleClicked (); }; center.ScheduleNotification (notification); }); }
private void InsertAlertNotification(string title, string msg) { using (var a = new NSAutoreleasePool()) { notificationCenter.BeginInvokeOnMainThread(delegate { NSUserNotification notification = new NSUserNotification(); notification.Title = title; notification.InformativeText = msg; NSMutableDictionary userInfo = new NSMutableDictionary(); userInfo.Add((NSString)notificationType, (NSString)notificationTypeAlert); notification.UserInfo = userInfo; notification.DeliveryDate = NSDate.Now; notificationCenter.DeliverNotification(notification); }); } }
public static void RaiseNotification(string title, string text) { // Trigger a local notification. // Configure the notification style in System Preferences. var notification = new NSUserNotification { Title = title, InformativeText = text, SoundName = NSUserNotification.NSUserNotificationDefaultSoundName, HasActionButton = false, HasReplyButton = false }; NSUserNotificationCenter.DefaultUserNotificationCenter.DeliverNotification(notification); }
partial void OnFetchButtonClick(NSButton sender) { var notification = new NSUserNotification(); // Add text and sound to the notification notification.Title = "CryptoNotifier - Price Alert"; notification.InformativeText = "Add your task to your activity log"; notification.Subtitle = "This is a subtitle"; notification.SoundName = NSUserNotification.NSUserNotificationDefaultSoundName; notification.HasActionButton = true; // Show "close" and "show" buttons when the notification is displayed as an alert notification.ActionButtonTitle = "Details"; NSUserNotificationCenter.DefaultUserNotificationCenter.DeliverNotification(notification); //await LoadAccountsData(); }
partial void NotifyMeAction (MonoMac.AppKit.NSButton sender) { // First we create our notification and customize as needed NSUserNotification not = null; try { not = new NSUserNotification(); } catch { new NSAlert { MessageText = "NSUserNotification Not Supported", InformativeText = "This API was introduced in OS X Mountain Lion (10.8)." }.RunSheetModal (this); return; } not.Title = "Hello World"; not.InformativeText = "This is an informative text"; not.DeliveryDate = DateTime.Now; not.SoundName = NSUserNotification.NSUserNotificationDefaultSoundName; // We get the Default notification Center 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; }; // If we return true here, Notification will show up even if your app is TopMost. center.ShouldPresentNotification = (c, n) => { return true; }; center.ScheduleNotification(not); }
protected override void NotifyUser(string title, string message, NotificationType type) { var notification = new NSUserNotification(); notification.Title = title; notification.InformativeText = message; notification.DeliveryDate = DateTime.Now; notification.SoundName = NSUserNotification.NSUserNotificationDefaultSoundName; // We get the Default notification Center var center = NSUserNotificationCenter.DefaultUserNotificationCenter; // TODO: Figure out why this does not work if (center == null) return; //center.DidDeliverNotification += (s, e) => { }; center.DidActivateNotification += (s, e) => { }; // If we return true here, Notification will show up even if your app is TopMost. center.ShouldPresentNotification = (c, n) => { return true; }; center.ScheduleNotification(notification); }
public void Notification(string title, string notes) { RequestAttention (); if (Engine.Instance.Storage.GetBool ("gui.osx.notifications") == false) return; // First we create our notification and customize as needed NSUserNotification not = null; try { not = new NSUserNotification(); } catch { // This API was introduced in OS X Mountain Lion (10.8) return; } not.Title = title; not.InformativeText = notes; not.DeliveryDate = DateTime.Now; not.SoundName = NSUserNotification.NSUserNotificationDefaultSoundName; // We get the Default notification Center NSUserNotificationCenter center = NSUserNotificationCenter.DefaultUserNotificationCenter; // If we return true here, Notification will show up even if your app is TopMost. center.ShouldPresentNotification = (c, n) => { return true; }; center.ScheduleNotification(not); }