最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

macos - python push a notify on mac - Stack Overflow

programmeradmin0浏览0评论

I'm trying to push notifies by python with objc on mac os(12.7.6).But i'm not familiar with objc , mac Notification api. i have written follow code

from UserNotifications import UNUserNotificationCenter, UNTimeIntervalNotificationTrigger, UNMutableNotificationContent, UNNotificationRequest, UNNotificationAction, UNNotificationActionOptions, UNNotificationCategory, UNNotificationCategoryOptions


center = UNUserNotificationCenter.currentNotificationCenter()
trigger = UNTimeIntervalNotificationTrigger(triggerWithTimeInterval=1, repeats=False)

content = UNMutableNotificationContent()
content.setTitle_('Main Title')
content.setSubTitle_('sub Title')
content.setBody_('message content')

content.setUserInfo_(["method", "new"])


acceptAction = UNNotificationAction(identifier="SHOW_ACTION", title="Show", options=UNNotificationActionOptions.UNNotificationActionOptionForeground)
declineAction = UNNotificationAction(identifier="declineAction", title="Close", options=UNNotificationActionOptions.UNNotificationActionOptionForeground)

testCategory = UNNotificationCategory(identifier="NOTIFICATION_DEMO", actions=[acceptAction, declineAction], intentIdentifiers=[], hiddenPreviewsBodyPlaceholder="", options=UNNotificationCategoryOptions.UNNotificationCategoryOptionCustomDismissAction)

request = UNNotificationRequest(identifier='NOTIFICATION_DEMO_REQUEST', content=content, trigger=trigger)

center.setNotificationCategories([testCategory])

center.add(request)

I want push a notify, then the notify window will display messages and two buttons, one is "Show", another is "Close". When pressed "Show" button , i want to do some action. Please help.

发布评论

评论列表(0)

  1. 暂无评论