Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NSUserNotificationCenter.defaultUserNotificationCenter() returning None using PyInstaller

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.

like image 371
Sameer Avatar asked May 25 '26 17:05

Sameer


1 Answers

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.

like image 90
Sameer Avatar answered May 28 '26 08:05

Sameer



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!