Reputation: 256
I have implemented ShowInAppSearchResultsIntent
and AppShortcutsProvider
that is newly launched by apple in WWDC24.
import AppIntents
import Foundation
import UIKit
@AssistantIntent(schema: .system.search)
struct CineverseSearchIntent: ShowInAppSearchResultsIntent {
// static var title: LocalizedStringResource = "Search in Cineverse for"
static var searchScopes: [StringSearchScope] = [.general]
@Parameter(requestValueDialog: IntentDialog("What would you like to search for?"))
var criteria: StringSearchCriteria
@MainActor
func perform() async throws -> some IntentResult {
let searchString = criteria.term
print("Searching for \(searchString)")
msgWithSingleButton(message: "Searching for \(searchString)", title: "Siri", buttonTitle: "OK")
return .result()
}
}
class AppShortcuts: AppShortcutsProvider {
static var appShortcuts: [AppShortcut] {
AppShortcut(
intent: CineverseSearchIntent(),
phrases: [
"using \(.applicationName) search for",
"search on \(.applicationName) app"
],
shortTitle: "Search Movie",
systemImageName: "sparkles"
)
}
}
//Alert
func msgWithSingleButton(message: String, title: String = "",buttonTitle : String){
let alertView = UIAlertController(title: title, message: message, preferredStyle: .alert)
alertView.addAction(UIAlertAction(title: buttonTitle, style: .default, handler: nil))
let scenes = UIApplication.shared.connectedScenes
let windowScene = scenes.first as? UIWindowScene
let window = windowScene?.windows.first
window?.rootViewController?.present(alertView, animated: true)
}
I have tried the above code. It is triggering the criteria in simulator(iOS 18.0). Siri is saying the phrase - "What would you like to search for?" - that i have implemented using @Parameter
, but after that it is not working.
But in real device it is directly opening the app and not calling the criteria. And showing error in console Failed to generate TargetContentIdentifier for criteria
.
Official Documentation url Apple Developer
This is the full code I have implemented. Please find the solution.
Upvotes: 2
Views: 178