title: Fetch preferences / permissions for NSUserNotificationCenter
body: <p>I'm currently trying to set up a notification service using the old <a href="https://developer.apple.com/documentation/foundation/nsusernotificationcenter" rel="nofollow noreferrer">NSUserNotification</a> API on macOSX (not iOS) in objective c++.
  The catch is that I would need to know the system preferences associated with notifications that the user set (and preferably during the rest of runtime too) to determine if my notifications are actually seen. The application is meant to get the users attention in some way to guarantee things like reminders don't go unnoticed, so the thing I want to avoid is a notification delivered that silently doesn't produce any sound nor image on the screen whatsoever without the application knowing. If the notification is not allowed the application should handle it in some other way.</p>
  
  <p>I am working on a macOS 10.14 Mojave machine. My overall code with NSUserNotificationCenter works fine with a custom Delegate that implements shouldDeliver, didActivate etc. Its just that I am currently assuming the user didn't press the "frick off" button on my notifications.</p>
  
  <p>Unfortunately, NSUserNotificationCenter and related classes don't appear to feature a function that determines the permissions the way the new API (<a href="https://developer.apple.com/documentation/usernotifications/unusernotificationcenter?language=objc" rel="nofollow noreferrer">UNUserNotificationCenter</a>) does. I have been trying to resolve this for a few hours so I was wondering if anyone else has found a solution to this. I can't really use the new API since this is strictly for back-compatibility in favour of the possibly rather prevalent amount of people who don't use mojave yet.</p>
  
  <p>Things I have tried to make it work so far:</p>
  
  <ul>
  <li><p>Try and see if there is a .plist somewhere where these settings are stored, in the User-specific Library folder as well as the general Library folder. </p></li>
  <li><p>Try and find said .plist using CFPreferencesCopyKeyList and related methods. Apparently I don't really know the right domain name.</p></li>
  <li><p><a href="https://stackoverflow.com/questions/11825063/nsusernotificationcenter-is-it-enabled">This answer</a> from 2012 which appears to be outdated since I cannot locate the database on my machine anymore. Might be due to me using a mojave machine, or the file has since moved somewhere else.</p></li>
  <li><p>Try and determine whether we can retro-actively check our permissions by checking a NSUserNotification's "presented" property on didDeliverNotification, shouldPresentNotification in the delegate. Unfortunately as stated in NSUserNotificationCenter itself it still behaves the same whether the preferences allow notifications or not.</p></li>
  </ul>
  
  <p>Some code I tried includes the following:</p>
  
  <pre><code>CFPreferencesCopyKeyList((CFStringRef) @"com.apple.systemPreferences.plist", kCFPreferencesCurrentUser, kCFPreferencesCurrentHost);
  
  CFPreferencesCopyKeyList((CFStringRef) @"com.apple.systemPreferences.plist", kCFPreferencesAnyUser, kCFPreferencesAnyHost);
  
  //Unfortunately returns null with any combination of com.apple.notificationcenter.plist, kCFPreferencesCurrentUser, kCFPreferencesCurrentHost
  CFPreferencesCopyKeyList((CFStringRef) @"com.apple.notificationcenter", kCFPreferencesAnyUser, kCFPreferencesAnyHost);
  </code></pre>