4 Lessons Learned in Handling User Notification in macOS

Harry Ng
macOS App Development
3 min readOct 26, 2016

Notification is one important feature in implementing a Full Circle application. Yet, the notification APIs are easy to use but lack of consistency. Here are some lessons I learn about in integrating notification to the macOS app I am working on.

1) Scheduled Notification Order is not guaranteed

Say I am sending 5 reminders at the same time, set in the property deliveryDate, the notification order is in random order. This situation only happens to scheduleNotification(_:) method in NSUserNotificationCenter.

In Apple’s documentation, it said:

Note that the user notification may be displayed later than the delivery date depending on a number of factors.

and it uses the actualDeliveryDate to sort the displayed notifications. Thus the system may have some random reasons to affect the sort order.

2) Repeat Interval

deliveryRepeatInterval can be set to control how often the user notification is sent again to the user. It is used together with deliveryDate. The learning here is that deliveryDate can be a past date when the notification object is created. Say I can set a date of 1970, and a repeat interval of every hour.

Also, be aware that if the current time is just right at the repeat interval. The first notification will happen immediately after you schedule the notification.

3) Additional Action Buttons

Since macOS 10.10, there is a new property additionalActions where developers can provide an array of actions which is shown in the menu like the Apple Reminders notification above. However, there are a few bugs in using this property (Tested with macOS 10.11 El Capitan):

  • removeScheduledNotification(_:)does not work properly for repeating reminder
  • removeAllDeliveredNotifications() does not remove the displayed notifications at top-right corner
  • The “Clear All” button in Notification Center cannot remove those notifications

Thus, likely this feature is not ready to be used.

4) Private APIs

To continue with the previous example in Apple Reminders, many of the features are not reproducible through the public APIs. For example:

  • Complete button is served as otherButton can take action
  • The triangle next to Later is shown during hover
  • Later itself does not take action, but rather shows the menu created by additionalActions
  • Subtitle in the content area can be updated regularly

Some of these features can be found in Private APIs in this example. Yet, using Private APIs may risk in not approved by Mac App Store. Use at your own risk.

--

--