ios – How you can ship a communication notification domestically, with out Push server?


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 shouldn’t be applied. Because of this, I exploit native notification sending. I discovered little or no info 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 way of Push notifications? In that case, this concern will be thought of closed. If not, why do I’ve a daily notification despatched, though I turned on the mandatory 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 get in touch with title (communication notifications) work just for Push notifications? I can not ship a push, solely an area notification. BUT I can not fashion the native notification below 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 possibly can 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.
    }
}

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles