Grouped notifications are a huge improvement for the notification system on iOS, which many users have eagerly been waiting for. However, if all notifications for a single app are grouped together, important information might get lost. If a messaging app stacks all notifications in a single group, it's easy to miss an important message if it's hidden somewhere in the group.
For this reason, Apple allows developers to create custom notification groups based on special thread identifiers. The most obvious use case is to group all notifications from a certain conversation in a messaging app together. However, there are other useful implementations of grouped notifications that you can come up with.
You could use thread identifiers to separate certain important, actionable notifications from a group of informative notifications. Doing this will make the important notifications stand out to the user, without cluttering the user's Notification Center with several less important informative messages.
To begin using grouped notifications, all you have to do is assign a thread identifier to a notification content object. For the Notifications app, it would be interesting to group notifications for bedtime and lunchtime notifications together. You can do this by assigning a thread identifier to the notification content object that is created by the notifications helper object. Update the implementation for addLunchTimeNotification() as follows to assign a thread identifier to a lunchtime notification:
@IBAction func addLunchTimeNotification() { persistentContainer.viewContext.perform { [unowned self] in // existing implementation ... let content = self.notificationsHelper.createNotificationContentForReminder(reminder) content.threadIdentifier = "lunchtime-thread" self.notificationsHelper.scheduleTimedNotificationWithContent(content) } }
Only a single line of code was added to implement a thread identifier. Try adding a thread identifier to the bedtime notification as well, and then run the app. Try scheduling a couple of bedtime and lunchtime notifications to see how iOS groups the notifications based on the thread identifier.