开发者

How to set local notification on Mac OS X?

开发者 https://www.devze.com 2023-04-06 22:32 出处:网络
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

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消