{"id":16312,"date":"2016-11-08T16:18:28","date_gmt":"2016-11-08T21:18:28","guid":{"rendered":"http:\/\/mjtsai.com\/blog\/?p=16312"},"modified":"2019-02-26T16:09:25","modified_gmt":"2019-02-26T21:09:25","slug":"how-to-badge-an-apps-icon-in-the-dock","status":"publish","type":"post","link":"https:\/\/mjtsai.com\/blog\/2016\/11\/08\/how-to-badge-an-apps-icon-in-the-dock\/","title":{"rendered":"How to Badge an App&rsquo;s Icon in the Dock"},"content":{"rendered":"<p><a href=\"https:\/\/eternalstorms.wordpress.com\/2016\/10\/29\/how-to-badge-an-apps-icon-in-the-dock\/\">Matthias Gansrigler<\/a>:<\/p>\n<blockquote cite=\"https:\/\/eternalstorms.wordpress.com\/2016\/10\/29\/how-to-badge-an-apps-icon-in-the-dock\/\">\n<p>Add this key-value pair to your <tt>Info.plist<\/tt>: <em>NSUserNotificationAlertStyle<\/em> with a string value of either <em>banner<\/em> (<a href=\"https:\/\/developer.apple.com\/library\/content\/documentation\/General\/Reference\/InfoPlistKeyReference\/Articles\/CocoaKeys.html#\/\/apple_ref\/doc\/uid\/TP40009251-SW19\">recommended<\/a> by Apple) or <em>alert<\/em>. Supposedly, there&rsquo;s another value, <em>none<\/em>, but that hasn&rsquo;t worked for me yet &#8211; the app won&rsquo;t appear in the Notifications preference pane.<\/p>\n<p>Having the key-value pair in your <tt>Info.plist<\/tt> has no downside if you don&rsquo;t use NSUserNotifications. There&rsquo;s only the upside of having the user be able to disable your app&rsquo;s badges if they like.<\/p>\n<\/blockquote>\n\n<p><a href=\"http:\/\/lapcatsoftware.com\/articles\/we-dont-need-no-stinking-badges.html\">Jeff Johnson<\/a>:<\/p>\n<blockquote cite=\"http:\/\/lapcatsoftware.com\/articles\/we-dont-need-no-stinking-badges.html\"><p>The documentation for <code>NSUserNotification<\/code> is sparse and implies that Notification Center handles everything automatically. The reality is that developers need to do almost everything themselves.<\/p><p>[&#8230;]<\/p><p>There is no API to determine whether the user has &ldquo;Badge app icon&rdquo; checked in System Preferences. I was stuck on that, but the trick here, which Rig discovered, is that when &ldquo;Badge app icon&rdquo; is unchecked, your app&rsquo;s calls to <code>setBadgeLabel:<\/code> will not actually set the badge label. This is analogous to <code>deliverNotification:<\/code> in that you should call the method regardless, and Notification Center determines whether anything happens as a result, according to the user&rsquo;s preferences.<\/p><\/blockquote>\n<p>However, you may still want your own preference for <a href=\"http:\/\/mjtsai.com\/blog\/2015\/05\/28\/textexpander-5\/\">privacy<\/a>.<\/p>\n<blockquote cite=\"http:\/\/lapcatsoftware.com\/articles\/we-dont-need-no-stinking-badges.html\"><p>You&rsquo;ll also need to call <code>[[NSApp dockTile] setBadgeLabel:nil]<\/code> in <code>applicationWillTerminate:<\/code> otherwise the Dock badge will remain visible after the app quits. And you may want to call it in <code>applicationDidFinishLaunching:<\/code> too, in case your app crashed before it could clear the previous badge.<\/p><\/blockquote>","protected":false},"excerpt":{"rendered":"<p>Matthias Gansrigler: Add this key-value pair to your Info.plist: NSUserNotificationAlertStyle with a string value of either banner (recommended by Apple) or alert. Supposedly, there&rsquo;s another value, none, but that hasn&rsquo;t worked for me yet &#8211; the app won&rsquo;t appear in the Notifications preference pane. Having the key-value pair in your Info.plist has no downside if [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"apple_news_api_created_at":"2019-02-26T21:09:29Z","apple_news_api_id":"34f1c4ce-8add-48cf-b0f4-ee162749d683","apple_news_api_modified_at":"2019-02-26T21:09:30Z","apple_news_api_revision":"AAAAAAAAAAD\/\/\/\/\/\/\/\/\/\/w==","apple_news_api_share_url":"https:\/\/apple.news\/ANPHEzordSM-w9O4WJ0nWgw","apple_news_coverimage":0,"apple_news_coverimage_caption":"","apple_news_is_hidden":false,"apple_news_is_paid":false,"apple_news_is_preview":false,"apple_news_is_sponsored":false,"apple_news_maturity_rating":"","apple_news_metadata":"\"\"","apple_news_pullquote":"","apple_news_pullquote_position":"","apple_news_slug":"","apple_news_sections":"\"\"","apple_news_suppress_video_url":false,"apple_news_use_image_component":false,"footnotes":""},"categories":[4],"tags":[1777,30,1381,111,71],"class_list":["post-16312","post","type-post","status-publish","format-standard","hentry","category-programming-category","tag-dock","tag-mac","tag-macos-10-12","tag-notificationcenter","tag-programming"],"apple_news_notices":[],"_links":{"self":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/16312","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/comments?post=16312"}],"version-history":[{"count":1,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/16312\/revisions"}],"predecessor-version":[{"id":16313,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/16312\/revisions\/16313"}],"wp:attachment":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/media?parent=16312"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/categories?post=16312"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/tags?post=16312"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}