I am struggling to ship a communication notification (with the sender’s avatar and his identify). I am making a shopper software for a third-party web site the place sending Push notifications shouldn’t be applied. In consequence, I exploit native notification sending. I discovered little or no info on the Web about these notifications, however the code I discovered would not work for me.
The query is, can communication notifications be despatched solely by Push notifications? If that’s the case, this subject might be thought of closed. If not, why do I’ve an everyday notification despatched, though I turned on the required Capabilities and added Message Intent to Data.plist.
To make clear, I haven’t got a backend server. I am simply asking if notifications with an avatar and speak to identify (communication notifications) work just for Push notifications? I am unable to ship a push, solely a neighborhood notification. BUT I am unable to fashion the native notification below the message fashion with the contact identify and avatar.
func didReceive(
request: UNNotificationRequest,
withContentHandler contentHandler: @escaping (UNNotificationContent
) -> Void) {
let deal with = INPersonHandle(worth: "unique-user-id)", sort: .unknown)
let sender = INPerson(personHandle: deal with,
nameComponents: nil,
displayName: "Title",
picture: nil, // right here you'll be able to present UIImage for consumer avatar
contactIdentifier: nil,
customIdentifier: "unique-user-id")
let intent = INSendMessageIntent(
recipients: nil,
outgoingMessageType: .outgoingMessageText,
content material: "content material of message",
speakableGroupName: nil,
conversationIdentifier: "unique-user-id-conv",
serviceName: nil,
sender: sender,
attachments: nil
)
let interplay = INInteraction(intent: intent, response: nil)
interplay.path = .incoming
interplay.donate(completion: nil)
let content material = request.content material
do {
let updatedContent = strive content material.updating(from: intent)
let mutableBestAttemptContent = (updatedContent.mutableCopy() as? UNMutableNotificationContent)!
mutableBestAttemptContent.threadIdentifier = "Thread-identifier" // use this subject for grouping notifications
mutableBestAttemptContent.userInfo = request.content material.userInfo
contentHandler(mutableBestAttemptContent)
} catch {
// Deal with errors that will happen whereas updating content material.
}
}