【发布时间】:2019-08-06 17:43:12
【问题描述】:
我正在尝试测试一个简单的 Python 脚本来发送 macOS 通知:
import UserNotifications
def notif_callback(err):
print("Error in notification callback:",err)
def auth_callback(granted, err):
print("Granted: ",granted,)
print("Error in authorization request: ",err)
content=UserNotifications.UNMutableNotificationContent.alloc().init()
content.setTitle_("Test")
r=UserNotifications.UNNotificationRequest.requestWithIdentifier_content_trigger_('test_notification',content,None)
c=UserNotifications.UNUserNotificationCenter.currentNotificationCenter()
c.requestAuthorizationWithOptions_completionHandler_(0b111111,auth_callback)
c.addNotificationRequest_withCompletionHandler_(r,notif_callback)
但是,当我尝试运行该程序时,它给出了以下错误
Granted: False
Error in authorization request: Error Domain=UNErrorDomain Code=1 "Notifications are not allowed for this application" UserInfo={NSLocalizedDescription=Notifications are not allowed for this application}
Error in notification callback: Error Domain=UNErrorDomain Code=1 "Notifications are not allowed for this application" UserInfo={NSLocalizedDescription=Notifications are not allowed for this application}
我没有看到来自我的系统的任何通知授权,并且操作系统似乎自动拒绝了该请求。在系统偏好设置中,Python 已被授予所有通知权限。我在这里错过了什么?
【问题讨论】:
-
如果有人有有效的答案,请发帖:stackoverflow.com/questions/62234033/…
标签: objective-c python-3.7 macos-mojave pyobjc