简体   繁体   中英

How to set local notification on Mac OS X?

I'm writing an app for mac os x, and I have to display a notification every day, to remind users about something. The notification should appear even if the app isn't running, and I can't use push notification.

I guess the best solution would be local notification, just like on iOS. Also I know UILocalNotification is available on iOS only. But I think there should be an alternative solution.

Can anybody please point me in the right direction? Is it even possible? If yes, what is the best practice to do this?

Local notifications support, very similar to iOS local notifications, has been added in MacOS 10.8 (Mountain Lion). See MacOSX10.8/Frameworks/Foundation.Framework/NSUserNotification.h for more information.
Quick usage example could be found here .

The notification should appear even if the app isn't running

Well, something will still have to be running to send the actual notification. Mostly helper programs are used for this (separate executable binaries that are added as launch agents or launch daemons). So I'm suggesting you create a daemon-like helper program that would be added as launch daemon on a per-user basis. You can also look at shared file list api to see how can it be added to user's login items.

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