简体   繁体   中英

Xamarin Mac OSX (os Sierra) local and push notifications in c#

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

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());

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM