问题
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