4

I have a ShareExtension in my iOS app. I am trying to use Suggestions. I can successfully 'donate' the intent using the following code from the apple developer website:

let groupName = INSpeakableString(spokenPhrase: "Juan Chavez")
let sendMessageIntent = INSendMessageIntent(recipients: nil,
                                            content: nil,
                                            speakableGroupName: groupName,
                                            conversationIdentifier: "sampleConversationIdentifier",
                                            serviceName: nil,
                                            sender: nil)

// Add the user's avatar to the intent.
let image = INImage(named: "Juan Chavez")
sendMessageIntent.setImage(image, forParameterNamed: \.speakableGroupName)

// Donate the intent.
let interaction = INInteraction(intent: sendMessageIntent, response: nil)
interaction.donate(completion: { error in
    if error != nil {
        // Add error handling here.
    } else {
        // Do something, e.g. send the content to a contact.
    }
})

This works fine and I am able to see my app icon in the suggestion row on the top for each conversation. However when I click on the suggestion, the intent property of the extentsionContext is nil:

override func viewDidLoad() {
        super.viewDidLoad()
        
        // Populate the recipient property with the metadata in case the user tapped a suggestion from the share sheet.
        let intent = self.extensionContext?.intent as? INSendMessageIntent
        if intent != nil { // this is nil despite selecting suggestion
            let conversationIdentifier = intent!.conversationIdentifier
            self.recipient = recipient(identifier: conversationIdentifier!)
        }
    }

My ShareExtension plist is as follows:

enter image description here

The other odd behaviour is that I'm able to do the donate from the main app but not from the app extension. In the main app the only relevant entry in the plist is the same NSUserActivityTypes entry. Not the NSExtension entries.

My understanding is that tapping on the suggestion, the extensionContext should contain the intent.

alionthego
  • 8,508
  • 9
  • 52
  • 125
  • do you have any updates or fixes about this issue? – Get Schwifty May 24 '22 at 16:17
  • The intent property doesn't even show when I initialize an instance of NSExtensionContent, as in the following code: ``` let extensionContext = NSExtensionContext() extensionContext.intent ``` I get an error saying: > > Value of type 'NSExtensionContext' has no member 'intent' – daniel Jul 05 '22 at 06:22
  • I followed the exact same article from apple but my app icon is not showing in suggestions. I donated an intent when user sent a message. – Awais Fayyaz Aug 22 '22 at 11:50

1 Answers1

0

I had the same problem and fixed it by using a real IOS Device. Looks like an issue with the IOS Simulator.. With the real device the intent value was not nil anylonger.

moriax
  • 11
  • 1
  • 2