0

I want to make an app that gives the user specific notifications at the specific time of day. My app is running Mac Cocoa/native Mac (not Xamarin Forms.) For example, if it is 3:00 and the mac is running but the program itself is not, and the user has a notification set for 3:00, I want the notification to run. I am a beginner so I don't know if this would have to be done through push or local notifications. For those of you with macs, this is what I am trying to do:

https://i.imgur.com/i8oyoan.jpg

SushiHangover
  • 73,120
  • 10
  • 106
  • 165

1 Answers1

1

You can schedule a NSUserNotification for a future time and it will be displayed even if the Cocoa app is not running.

NSUserNotification Example:

This will schedule a notification for 30 seconds in the future and terminate the app, 30 seconds later you will receive a notification and it will also be added to the notification center.

var note = new NSUserNotification
{
    Title = "StackOverflow",
    DeliveryDate = NSDate.FromTimeIntervalSinceNow(30)
        
};
NSUserNotificationCenter.DefaultUserNotificationCenter.ScheduleNotification(note);
NSApplication.SharedApplication.Terminate(new NSObject());
Community
  • 1
  • 1
SushiHangover
  • 73,120
  • 10
  • 106
  • 165
  • Would this method also work on mobile, or at least iOS? Just wondering :) – Humzah Merchant Apr 29 '17 at 17:55
  • @HumzahMerchant In iOS10+ they added the UserNotifications framework and you now use `UNNotificationRequest` via `UNUserNotificationCenter.AddNotificationRequest`, in iOS9 and under you use `UILocalNotification` – SushiHangover Apr 29 '17 at 18:25