I have a simple list app called 'SiriTest', which I can add items to by saying "Hey Siri, add to SiriTest'. I will be prompted to speak the item, and the item will be added, Siri will speak confirmation and close.
If I instead activate Siri by holding down the power button, I will be prompted to speak an item, the item will be added to the list, but the Siri dialogue screen remains open with "One moment...." or "One sec...", and no confirmation until I press elsewhere on the screen.
How do I get the confirmation from Siri and dismiss Siri dialogue when using Siri via holding phone side power button?
import AppIntents
import SwiftUI
@available(iOS 16, *)
struct AddItemIntent: AppIntent {
static var title: LocalizedStringResource = "Add item"
@Parameter(title: "Item name")
var itemName: String
@MainActor
func perform() async throws -> some ProvidesDialog {
DispatchQueue.main.async {
ItemModel.shared.addItem(itemName: itemName)
}
return .result(
dialog: "Added to your list."
)
}
}
@available(iOS 16.0, *)
struct ListShortcuts: AppShortcutsProvider {
static var appShortcuts: [AppShortcut] {
AppShortcut(
intent: AddItemIntent(),
phrases: [
"Add item to \(.applicationName)",
"Add to \(.applicationName)",
]
)
}
}
import Foundation
class ItemModel: ObservableObject {
static let shared: ItemModel = ItemModel()
@Published var list: [String] = []
init() {
dummyItems()
}
func addItem(itemName: String) {
list.append(itemName)
}
func dummyItems() {
list.append(contentsOf: ["One", "Two", "Three"])
}
}
import SwiftUI
struct ContentView: View {
@EnvironmentObject var itemModel: ItemModel
var body: some View {
List(itemModel.list, id: \.self) {item in
Text(item)
}
}
}
import SwiftUI
@main
struct SiriTestApp: App {
var body: some Scene {
WindowGroup {
ContentView()
.environmentObject(ItemModel.shared)
}
}
}