NSUserNotificationCenter.defaultUserNotificationCenter() returning None using PyInstaller
Asked Answered
I

1

3

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.

Indehiscent answered 8/8, 2014 at 13:36 Comment(1)
A similar problem on py2app sometime back #19678842Liebknecht
I
3

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.

Indehiscent answered 11/8, 2014 at 13:12 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.