Style of NSUserNotification
Asked Answered
O

1

13

A NSUserNotification only shows the action button if the user sets the style of the notifications for my app to "alerts" in the system preferences. Can I somehow set this style for my application as a default instead of relying on the user to manually select it?

Ortiz answered 6/8, 2012 at 15:35 Comment(0)
E
11

It took me a while to track down how to accomplish this in my own app.
According to Apple's info.plist keys reference:

NSUserNotificationAlertStyle Specifies whether the notification style should be banners, alerts, or none. The default value is banners, which is the recommended style.

In your case you need to define the key NSUserNotificationAlertStyle in info.plist with the value alert.

Errantry answered 17/8, 2012 at 20:39 Comment(7)
I have opened up a question in the Apple Dev Forums about this. If you see this you might want to check it to see if anything gets figured out. devforums.apple.com/message/745079#745079Preceptive
To summarize the thread at Apple Dev Forums: you need to code-sign your app, and set the style to alert in the info.plist.Heave
@SmilinBrian But how would you test this feature while you are developing your app? We usually sign not before publishing in the app store.Misdeem
@MikeLischke Since code-signing is required to make it work, it seems pretty obvious that you will have to code-sign in order to test it.Heave
This is totally impractal. In an organization where signing is done by someone else (say by the build team) no developer can sign the app just for testing. Not well thought out, I'd say.Misdeem
You can (and should) sign your app with your “Mac Developer” key for development and testing. In your target's build settings, set “Code Signing Identity” to Automatic/Mac Developer. When it's time to ship the app, the build team builds an archive and exports the app from the archive. When exporting, Xcode (or xcodebuild) can resign the app with a Mac App Store certificate or a Developer ID certificate.Chaffin
how exactly do I need to sign the app? I've signed it with Developer ID certificate and it still doesn't set it to alert type automatically when I allow notifications in system banner. I also set NSUserNotificationAlertStyle to alert in plist and tried other fresh computers and deleting app from notifications settings on mine. nothing. either it is signing has no effect or something else :( please helpChina

© 2022 - 2024 — McMap. All rights reserved.