I am struggling to ship a communication notification (with the sender’s avatar and his title). I am making a consumer utility for a third-party website the place sending Push notifications is just not carried out. Because of this, I take advantage of native notification sending. I discovered little or no data on the Web about these notifications, however the code I discovered does not work for me.
The query is, can communication notifications be despatched solely by means of Push notifications? In that case, this situation will be thought of closed. If not, why do I’ve a daily notification despatched, though I turned on the required Capabilities and added Message Intent to Information.plist.
To make clear, I haven’t got a backend server. I am simply asking if notifications with an avatar and speak to title (communication notifications) work just for Push notifications? I am unable to ship a push, solely an area notification. BUT I am unable to fashion the native notification beneath the message fashion with the contact title and avatar.
func didReceive(
request: UNNotificationRequest,
withContentHandler contentHandler: @escaping (UNNotificationContent
) -> Void) {
let deal with = INPersonHandle(worth: "unique-user-id)", kind: .unknown)
let sender = INPerson(personHandle: deal with,
nameComponents: nil,
displayName: "Identify",
picture: nil, // right here you'll be able to present UIImage for person 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 = attempt content material.updating(from: intent)
let mutableBestAttemptContent = (updatedContent.mutableCopy() as? UNMutableNotificationContent)!
mutableBestAttemptContent.threadIdentifier = "Thread-identifier" // use this area for grouping notifications
mutableBestAttemptContent.userInfo = request.content material.userInfo
contentHandler(mutableBestAttemptContent)
} catch {
// Deal with errors that will happen whereas updating content material.
}
}