Search intent using ShowInAppSearchResultsIntent

ShowInAppSearchResultsIntent is supported from iOS 17.2. However while consuming the API without @AssistantIntent(schema: .system.search) it throws a error as shown below.

I am looking for a way I can make use of ShowInAppSearchResultsIntent in iOS 17 without having to use iOS 18 APIs for @AssistantIntent(schema: .system.search). Is there any way to achieve this?

Yes. The compiler is complaining because you haven't specified a title.

struct SearchIntent: ShowInAppSearchResultsIntent {
    static let title: LocalizedStringResource = "Search App"
    
    static let searchScopes: [StringSearchScope] = [.general]
    
    static var openAppWhenRun: Bool = true
    
    @Parameter(title: "Search Text")
    var criteria: StringSearchCriteria
    
    @MainActor func perform() async throws -> some IntentResult {
        
        return .result()
    }
}

The above should compile for you. To find out how to conform to a protocol, ⌘ + click on the protocol (ShowInAppSearchResultsIntent) to see what is required in the docs.

Please specify the schema :

@AssistantIntent(schema: .system.search)

Also specify the scope :

static let searchScopes: [StringSearchScope] = [.general]

** If you would like to implement the same prior to iOS 18** , you can conform to AppIntent rather ShowInAppSearchResultsIntent.

You can have a parameter that takes in a line of text :

@Parameter(title: "Enter the search text:", inputOptions: String.IntentInputOptions.init(multiline: false))
var helpText: String

Sample Code :

struct SearchIntent: AppIntent {

static let title: LocalizedStringResource = "Search"

static var openAppWhenRun: Bool = false

@Parameter(title: "Enter the search text", inputOptions: String.IntentInputOptions.init(multiline: false)) var searchText: String

@MainActor func perform() async throws -> some IntentResult { // & ProvidesDialog & ShowsSnippetView //Do your processing here return .result(result: "I found something related to your search (searchText)") } }

Search intent using ShowInAppSearchResultsIntent
 
 
Q