How to show group name in the subtitle of the Communication Notification?

Hi all,

I am trying to display the name of the group in the subtitle of the communication notification, like this:

Here is my code:

    override func didReceive(_ request: UNNotificationRequest, withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void) {

        self.contentHandler = contentHandler

        var personNameComponents = PersonNameComponents()

        personNameComponents.nickname = "Test Person"

        let avatar = INImage(url: URL(string: "https:imageURL")!)

        let senderPerson = INPerson(personHandle: INPersonHandle(value: "1233211234", type: .unknown), nameComponents: personNameComponents, displayName: "Test Person", image: avatar, contactIdentifier: nil, customIdentifier: nil, isMe: false, suggestionType: .none)

        let mePerson = INPerson( personHandle: INPersonHandle(value: "1233211232", type: .unknown), nameComponents: nil, displayName: nil, image: nil, contactIdentifier: nil, customIdentifier: nil, isMe: true, suggestionType: .none)

        let incomingMessagingIntent = INSendMessageIntent(recipients: [mePerson], outgoingMessageType: .unknown, content: "Test", speakableGroupName: INSpeakableString(spokenPhrase: "Test Group"), conversationIdentifier: "Test Group", serviceName: "Test", sender: senderPerson, attachments: nil)

        incomingMessagingIntent.setImage(avatar, forParameterNamed: \.sender)

        let interaction = INInteraction(intent: incomingMessagingIntent, response: nil)

        interaction.direction = .incoming


        do {

            let newContent = try request.content.updating(from: incomingMessagingIntent) as! UNMutableNotificationContent
            contentHandler(newContent)
        } catch {
            print(error)
        }
    }

I also have tried:

  1. Setting the subtitle of the UNMutableNotificationContent
  2. Including the subtitle field in the aps remote notification payload

When I display the notification as a normal notification the subtitle is displayed as usual. What am I doing incorrectly?

Answered by wjd_by in 691084022

change your code to:

// recipients count > 1 
let incomingMessagingIntent = INSendMessageIntent(recipients: [mePerson,senderPerson], outgoingMessageType: .unknown, content: "Test", speakableGroupName: INSpeakableString(spokenPhrase: "Test Group"), conversationIdentifier: "Test Group", serviceName: "Test", sender: senderPerson, attachments: nil)
//  ParameterNamed is speakableGroupName
incomingMessagingIntent.setImage(avatar, forParameterNamed: \.speakableGroupName)
code-block
Accepted Answer

change your code to:

// recipients count > 1 
let incomingMessagingIntent = INSendMessageIntent(recipients: [mePerson,senderPerson], outgoingMessageType: .unknown, content: "Test", speakableGroupName: INSpeakableString(spokenPhrase: "Test Group"), conversationIdentifier: "Test Group", serviceName: "Test", sender: senderPerson, attachments: nil)
//  ParameterNamed is speakableGroupName
incomingMessagingIntent.setImage(avatar, forParameterNamed: \.speakableGroupName)
code-block

hi can you give me your code Dome

How to show group name in the subtitle of the Communication Notification?
 
 
Q