【问题标题】:NSUserNotificationCenter.defaultUserNotificationCenter() returning None using PyInstallerNSUserNotificationCenter.defaultUserNotificationCenter() 使用 PyInstaller 返回 None
【发布时间】:2014-08-08 13:36:23
【问题描述】:

我正在尝试将通知发送到通知中心 (Mac OSX) 我正在使用 PyObjC 绑定来使用我们 Python 应用程序中的可可 api。

我正在使用以下代码 sn-p :

import Foundation¬
import objc¬

NSUserNotification = objc.lookUpClass('NSUserNotification')¬
NSUserNotificationCenter = objc.lookUpClass('NSUserNotificationCenter')¬

notification = NSUserNotification.alloc().init()¬
notification.setTitle_("TestTitle")¬
notification.setInformativeText_("This is sample text")¬
center = NSUserNotificationCenter.defaultUserNotificationCenter()¬
center.deliverNotification_(notification)¬

当我直接从 python 上面运行时,它运行良好并在通知中心显示通知。但是,当我使用 PyInstaller 打包上述程序以准备二进制文件并运行时,它会出现以下错误。

AttributeError: 'NoneType' object has no attribute 'deliverNotification_'

这意味着我没有得到默认用户通知中心的对象。

有人遇到过这个问题吗?

提前致谢。

【问题讨论】:

标签: python macos pyinstaller pyobjc


【解决方案1】:

找到了答案。事实证明,我们需要在 App 的 Info.plist 文件中定义的“CFBundleIdentifier”键,默认情况下 PyInstaller 生成的 plist 文件中不存在该键。否则应用无法访问通知中心。

【讨论】:

    猜你喜欢
    • 2013-04-07
    • 2018-01-16
    • 1970-01-01
    • 1970-01-01
    • 2018-01-04
    • 1970-01-01
    • 2022-11-21
    • 1970-01-01
    • 2020-03-12
    相关资源
    最近更新 更多