admin管理员组文章数量:1390822
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.
本文标签: macospython push a notify on macStack Overflow
版权声明:本文标题:macos - python push a notify on mac - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744696830a2620329.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论