Created
July 27, 2026 17:56
-
-
Save simonbs/e470b44b2b0b86accbf5a8cd8eeeb379 to your computer and use it in GitHub Desktop.
Setting a custom icon on an otification
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| struct NotificationIconPresenter { | |
| func content(from content: UNMutableNotificationContent, iconFileURL: URL) -> UNNotificationContent? { | |
| guard let icon = INImage(url: iconFileURL) else { | |
| return nil | |
| } | |
| let senderName = Self.senderName(for: content) | |
| let sender = INPerson( | |
| personHandle: INPersonHandle(value: senderName, type: .unknown), | |
| nameComponents: nil, | |
| displayName: senderName, | |
| image: icon, | |
| contactIdentifier: nil, | |
| customIdentifier: senderName | |
| ) | |
| let intent = INSendMessageIntent( | |
| recipients: nil, | |
| outgoingMessageType: .outgoingMessageText, | |
| content: nil, | |
| speakableGroupName: nil, | |
| conversationIdentifier: Self.conversationIdentifier(for: content), | |
| serviceName: nil, | |
| sender: sender, | |
| attachments: nil | |
| ) | |
| intent.setImage(icon, forParameterNamed: \INSendMessageIntent.sender) | |
| return try? content.updating(from: intent) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment