iOS 12: Grouping Notifications

Yuri
e-Legion
Published in
4 min readJul 24, 2018

This article, as the previous one, is about Notification changes in iOS12. In the previous article, I talked about general updates, I will now focus more specifically on grouping notifications.

Grouping in iOS 12

To group your app’s notifications you don’t have to do anything — iOS 12 does that automatically. Notifications gather into a stack when there are 5 or more.

Users can choose grouping options through the system settings:

  • Automatic (by default) — app controls the grouping settings.
  • By App — app settings are ignored, all of the notifications from the same app pack into a single stack.
  • Off — app settings are ignored, notification grouping is off.

Grouping setting

We can affect message grouping only through using the Automatic сheck box in settings. In order to do that we need to assign a thread-id parameter in the notification. To illustrate that, let’s set the thread-id to the subtitle variable of notification:

Send a few messages and view the result:

It is also possible to pass the thread-id using the push notification.

When specifying an identifier on the notification, don’t forget to do that in the UNNotificationCategory, otherwise, notifications will not process in Extension.

There is another new feature of iOS12: for a category, you can specify the format of a message that will display on the user’s device. This can only be done through the initialization of the category.

The %u parameter is responsible for the number of messages in a group. It can be modified using summaryArgumentCount. For example, your newly published kitties digest consists of 10 pictures. It makes little sense to send 10 pushes to the user; better send one message with a counter equal to 10. %@ parameter displays the meaning of the summaryArgument variable.

There are 3 new messages in each group, but because the summaryArgumentCount parameter is specified, the number of messages displayed equals 20. The summaryArgument enables us to add the name of a category for which push-notifications are related to. Sounds good, doesn’t it? But now we have an issue with localization.

Localization

In order to solve the localization issue, let’s add a Stringdict File into the project.

Change the Localized String Key to the NOTIFICATION_SUMMARY, otherwise, the value from the dictionary will not be processed (despite any key with a dictionary name, which is passed as a parameter of a localized string). The rest of the values are shown in the picture:

Choose Localize for the dictionary in File Inspector:

Specify files for localization:

Go into project settings and add for example Russian (ru) for localization:

Unnecessary files can be removed from the project:

We have a localized string in the code. Pass it as a categorySummaryFormat parameter.

Getting a great app localization as a result!

A project created for the previous article has been updated, and you can have a look at the code on GitHub. Two presentations at WWDC were devoted to notification implementation: What’s New in User Notifications and Using Grouped Notifications.

We have a chance to discuss new features at MBLT DEV, occurring on the 28th of September in Moscow. Grab your ticket now: next Saturday the price is going to be higher!

--

--