Hi all,
I am trying to implement the communication notification for me app. But the avatar does not show and there is virtually no difference from a normal notification.
I also added the Communication Notification capability, and in my Notification Service Extension's Info.plist, added this: NSExtension → NSExtensionAttributes (dictionary) → IntentsSupported (array) → INSendMessageIntent (string)
What am I doing wrong?
Here is my code:
class NotificationService: UNNotificationServiceExtension {
var contentHandler: ((UNNotificationContent) -> Void)?
var bestAttemptContent: UNMutableNotificationContent?
override func didReceive(_ request: UNNotificationRequest, withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void) {
var personNameComponents = PersonNameComponents()
personNameComponents.nickname = "Sender Name"
let avatar = INImage(named: "Cover")
let senderPerson = INPerson(personHandle: INPersonHandle(value: "1233211234", type: .unknown), nameComponents: personNameComponents, displayName: "Sender Name", 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: .outgoingMessageText, content: "Test DUde", speakableGroupName: nil, conversationIdentifier: "uid", serviceName: "caset", sender: senderPerson, attachments: [])
incomingMessagingIntent.setImage(avatar, forParameterNamed: \.sender)
let interaction = INInteraction(intent: incomingMessagingIntent, response: nil)
interaction.direction = .incoming
do {
let newContent = try request.content.updating(from: incomingMessagingIntent)
contentHandler(newContent)
} catch {
print(error)
}
}
override func serviceExtensionTimeWillExpire() {
// Called just before the extension will be terminated by the system.
// Use this as an opportunity to deliver your "best attempt" at modified content, otherwise the original push payload will be used.
if let contentHandler = contentHandler, let bestAttemptContent = bestAttemptContent {
contentHandler(bestAttemptContent)
}
}
}