UNNotificationServiceExtension Not Displaying Sender Image

I created a Notification Service Extension to display profile images in place for the app image (i.e. iMessage).

I send a remote push notification via Firebase Functions, and in the payload, the relevant profile image url string. The profile image url string in the payload is successfully delivered as it appears in my console log and AppDelegate didReceiveRemoteNotification function.

My problem is the profile image does not replace the default app icon image in the remote push notification.

Below is my configuration. Any guidance would be appreciated!

Main target app: the info plist contains NSUSerActivityTypes = [INSendMessageIntent]. The Communications Notifications capability is enabled and "Copy only when installing" in Build Phases Embed Foundation Extensions

Notification Service Extension plist: contains NSExtension > NSExtensionAttributes > IntentsSupported > INSendMessageIntent.

Notification Service Extension class code:


 var contentHandler: ((UNNotificationContent) -> Void)?
 var bestAttemptContent: UNMutableNotificationContent?

 override func didReceive(_ request: UNNotificationRequest, withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void) {
     self.contentHandler = contentHandler
     bestAttemptContent = (request.content.mutableCopy() as? UNMutableNotificationContent)

     guard var bestAttemptContent = bestAttemptContent else { return }

     guard let fcmOptions = bestAttemptContent.userInfo["fcm_options"] as? [String: Any],
           let attachmentUrlAsString = fcmOptions["imageURL"] as? String else {

         contentHandler(bestAttemptContent)
         return
     }

     if let attachmentUrl = URL(string: attachmentUrlAsString) {

         var senderNameComponents = PersonNameComponents()
         senderNameComponents.nickname = bestAttemptContent.title

         let profileImage = INImage(url: attachmentUrl)

         let sender = INPerson(personHandle: INPersonHandle(value: "1233211234", type: .unknown), nameComponents: senderNameComponents, displayName: bestAttemptContent.title, image: profileImage, contactIdentifier: nil, customIdentifier: nil, isMe: false)
         let receiver = INPerson(personHandle: INPersonHandle(value: "1233211234", type: .unknown), nameComponents: nil, displayName: nil, image: nil, contactIdentifier: nil, customIdentifier: nil, isMe: true)

         let intent = INSendMessageIntent(
             recipients: [receiver],
             outgoingMessageType: .outgoingMessageText,
             content: "Test",
             speakableGroupName: INSpeakableString(spokenPhrase: "Sender Name"),
             conversationIdentifier: "sampleConversationIdentifier",
             serviceName: nil,
             sender: sender,
             attachments: nil
         )

         intent.setImage(profileImage, forParameterNamed: \.sender)

         let interaction = INInteraction(intent: intent, response: nil)
         interaction.direction = .incoming

         interaction.donate(completion: nil)

         if #available(iOSApplicationExtension 15.0, *) {

             do {
                 bestAttemptContent = try bestAttemptContent.updating(from: intent) as! UNMutableNotificationContent
             } catch {
                 contentHandler(bestAttemptContent)
                 return
             }
         }

         contentHandler(bestAttemptContent)

     } else {

         contentHandler(bestAttemptContent)
         return
     }
 }
 }    
UNNotificationServiceExtension Not Displaying Sender Image
 
 
Q