NSUserNotificationCenter.defaultUserNotificationCenter() returning None using PyInstaller

早过忘川 提交于 2020-01-13 13:35:11

问题


I am trying to put notification to notification centre (Mac OSX) I am using PyObjC bindings to use cocoa api's from our python application.

I am using following code snippet :

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)¬

When I run above directly from python it runs fine and shows notification in notification centre. However when I package above program using PyInstaller to prepare binary and run it gives following error.

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

This means I am not getting object of default user notification centre.

Has somebody come across this problem?

Thanks in advance.


回答1:


Found an answer. Turns out we need 'CFBundleIdentifier' Key defined in App's Info.plist file which is not present by default in PyInstaller's generated plist file. Otherwise app does not get an access to Notification Center.



来源:https://stackoverflow.com/questions/25204797/nsusernotificationcenter-defaultusernotificationcenter-returning-none-using-py

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!