Notification Service Extension is not calling in ionic capacitor (iOS) project.

Dear Team, 

We are trying to integrate Rich Push Notification in ionic capacitor project. As per instructions, we created/added notification service extension. But it is not calling notification service and not displaying images in push notification. 

Below is the source code written to download image from the url (shared via payload)

 

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

        self.contentHandler = contentHandler

        bestAttemptContent = (request.content.mutableCopy() as? UNMutableNotificationContent)

       

    

        if let bestAttemptContent = bestAttemptContent {

            if let attachmentString = bestAttemptContent.userInfo["media_attachment"] as? String,

                let attachmentUrl = URL(string: attachmentString) {

                let session = URLSession(configuration: URLSessionConfiguration.default)

                let downloadTask = session.downloadTask(with: attachmentUrl, completionHandler: { (url, _, error) in

                    if let error = error {

                        print("Error downloading attachment: \(error.localizedDescription)")

                    } else if let url = url {

                        let attachment = try! UNNotificationAttachment(identifier: attachmentString,

                                                                       url: url,

                                                                       options: [UNNotificationAttachmentOptionsTypeHintKey: kUTTypePNG])

                        bestAttemptContent.attachments = [attachment]

                    }

                    contentHandler(bestAttemptContent)

                })

                downloadTask.resume()

                }

        }

    }

 

Payload:

{

    "alert": {

      "title": "Test",

      "subtitle": "Test test",

      "body": "This episode we talk about Clean Architecture with Antonio Leiva."

    },

    "mutable-content": 1

  },

  "media_attachment": "https://koenig-media.raywenderlich.com/uploads/2016/11/Logo-250x250.png"

}

 

POD File:

 

target "NotificationService" do

  pod 'AirshipExtensions/NotificationService'

end

Didn't find what you were looking for?

New post

Comments

1 comment

  • Hello,

    Thank you for reaching out our support.

    When adding the notification service extension, make sure to add use_frameworks! in your podfile and then proceed with a pod update command.
    This will allow you within Xcode to have the framework in your NotificationService target.

    Comment actions Permalink
    0

Please sign in to leave a comment.