Let’s take quick dive in Grouped Notifications — iOS 12

Ashish Kakkad
2 min readJun 15, 2018

iOS 12 have Grouped Notifications!

“A group of four laughing men sits on an edge overlooking a green valley” by Matheus Ferrero on Unsplash

Thread Identifier

Create notification content with threadIdentifier to create group of that notification. Group will be of the application or specific topic from an application.

// Creating Groups with Thread Identifiers
let content = UNMutableNotificationContent()
content.title = "Notifications Group"
content.body = "Tutorial by Ashish Kakkad"
content.threadIdentifier = "notify-team-ios"

Notification payload will be like this

{
"aps" : {
"alert" : {
"title" : "Notifications Group",
"body" : "Tutorial by Ashish Kakkad"
}
"thread-id" : "notify-team-ios"
}
}

Give meaningful name to thread identifier for specific purpose of group.

Summary of group

Simple Notification Group Summary

let summaryFormat = "%u more messages"
return UNNotificationCategory(identifier: "category-identifier", actions: [], intentIdentifiers: [], hiddenPreviewsBodyPlaceholder: nil, categorySummaryFormat: summaryFormat, options: [])

Hidden Previews Summary Customization

let summaryFormat = "%u more messages"
let hiddenPreviewsPlaceholder = "%u messages"
return UNNotificationCategory(identifier: "category-identifier", actions: [], intentIdentifiers: [], hiddenPreviewsBodyPlaceholder: hiddenPreviewsPlaceholder, categorySummaryFormat: summaryFormat, options: [])

Notification Group Summary with Arguments

let summaryFormat = "%u more messages from %@"
return UNNotificationCategory(identifier: "group-messages", actions: [], intentIdentifiers: [], hiddenPreviewsBodyPlaceholder: nil, categorySummaryFormat: summaryFormat, options: [])

Notification Group Summary Argument

let content = UNMutableNotificationContent()
content.body = "…"
content.threadIdentifier = "notify-team-ios"
content.summaryArgument = "Ashish"

Notification Summary with Argument Count

let content = UNMutableNotificationContent()
content.body = "…"
content.threadIdentifier = "notify-team-ios"
content.summaryArgument = "Ashish"
content.summaryArgumentCount = 2

Updated notification payload will be like this

{
"aps” : {
"alert” : {
"body” : "…",
"summary-arg" : "Ashish",
"summary-arg-count" : 2

},
"thread-id" : "notify-team-ios"
}
}

Conclusion

I know that I haven’t described anything in detail. If I get time I will update this blog with details.

Happy Coding 🙂

If you have any questions, comments, suggestions or feedback then contact me on Twitter @ashishkakkad8. Also you can read my other blogs on my website ashishkakkad.com.

--

--