Notice: Undefined index: iOS12 in /var/sites/ on line 108
How to group user notifications using threadIdentifier and summaryArgument - free Swift 5.4 example code and tips

BLACK FRIDAY SALE: Save 50% on all my Swift books and bundles! >>

How to group user notifications using threadIdentifier and summaryArgument

Swift version: 5.6

Paul Hudson    @twostraws   

If your app shows notifications that can be split into sensible groups – such as messages from a person, updates for a news story, scores from a sports match, and so on on – you can have iOS group them together using the threadIdentifier and summaryArgument properties of UNMutableNotificationContent. iOS will then show those messages together, rather than in a long chain mixed up with other messages.

For example, you might write code like this:

let content = UNMutableNotificationContent()
content.title = reminder.title
content.threadIdentifier = "F39-C521-A7A"

The “F39-C521-A7A” part is a free text string – it won’t be shown to users, but it’s what allows iOS to group things together so it should be unique enough that you don’t get message crossover. If you were building a messaging app you might use the user’s unique identifier for your notification rather than their name, to avoid two messages from different people called Andrew being grouped together.

If you want to customize this further, you can also set the summaryArgument property of your notification content. This is a string that is shown to users, so you might write something like this:

content.summaryArgument =

That will make iOS write something “5 more alerts from Andrew” in small text underneath the alert, which helps make it clear to users which reminder group that alert belongs to.

Save 50% in my Black Friday sale.

SAVE 50% To celebrate Black Friday, all our books and bundles are half price, so you can take your Swift knowledge further without spending big! Get the Swift Power Pack to build your iOS career faster, get the Swift Platform Pack to builds apps for macOS, watchOS, and beyond, or get the Swift Plus Pack to learn advanced design patterns, testing skills, and more.

Save 50% on all our books and bundles!

Sponsor Hacking with Swift and reach the world's largest Swift community!

Available from iOS 12.0 – learn more in my book

Similar solutions…

About the Swift Knowledge Base

This is part of the Swift Knowledge Base, a free, searchable collection of solutions for common iOS questions.

Buy Pro Swift Buy Pro SwiftUI Buy Swift Design Patterns Buy Testing Swift Buy Hacking with iOS Buy Swift Coding Challenges Buy Swift on Sundays Volume One Buy Server-Side Swift Buy Advanced iOS Volume One Buy Advanced iOS Volume Two Buy Advanced iOS Volume Three Buy Hacking with watchOS Buy Hacking with tvOS Buy Hacking with macOS Buy Dive Into SpriteKit Buy Swift in Sixty Seconds Buy Objective-C for Swift Developers Buy Beyond Code

Was this page useful? Let us know!

Average rating: 962367.7/5

Unknown user

You are not logged in

Log in or create account

Link copied to your pasteboard.