Я пытаюсь настроить ярлыки и аппараты, чтобы позволить пользователю вызвать Siri и открыть диалог для создания новой записи с двумя или более атрибутами модели SwiftData. Я успешно кодировал для Siri, чтобы открыть приложение и для того, чтобы Siri открыла приложение и перейти на страницу, чтобы добавить запись, но не смог захватить ответ пользователя из приглашения Siri и сохранить его в новые записи. Если это рассматривается в Apple Docs и примерах, я не смог его найти. < /P>
Вот что у меня есть: < /p>
@Model
class Thing {
var name: String = ""
var comment: String = "no comment"
var recordType: String = "0"
var count: Int = 0
init(name: String, comment: String, recordType: String, count: Int) {
self.name = name
self.comment = comment
self.recordType = recordType
self.count = count
}
}//class
struct CreateNewThing: AppIntent {
static var title: LocalizedStringResource = "Create New Thing"
static var description = IntentDescription("Opens the app and moves to the Add Thing screen.")
static var openAppWhenRun: Bool = true
@AppStorage("navigateToThingAddView") private var navigateToThingAddView: Bool = false
@MainActor
func perform() async throws -> some IntentResult {
navigateToThingAddView = true
return .result()
}
}//create new thing
struct ThingAddDialog: AppIntent {
static var title: LocalizedStringResource = "Add Thing Dialog"
static var description = IntentDescription("Prompt the user for a name and comment for a new Thing.")
static var openAppWhenRun: Bool = true
@Parameter(title: "Name", default: "")
var name: String
@Parameter(title: "Comment", default: "No comment")
var comment: String
@MainActor
func perform() async throws -> some ProvidesDialog & ShowsSnippetView {
// Logic to navigate to the Add Thing dialog view
//navigateToThingDialog = true
let dialog = IntentDialog(
full: "What is the name of the new Thing?",
supporting: "I have opened the Add Thing Dialog.")
let answer = $name.needsValueError("Provide a name")
name = answer.description
saveThing(name: name, comment: comment)
return .result(dialog: dialog)
}
@MainActor
private func saveThing(name: String, comment: String) {
let newThing = Thing(name: name, comment: comment, recordType: "0", count: 0)
// Add newThing to SwiftData
let container = try! ModelContainer(for: Thing.self)
container.mainContext.insert(newThing)
try? container.mainContext.save()
}
}
struct ThingShortcuts: AppShortcutsProvider {
static var shortcutTileColor = ShortcutTileColor.navy
static var appShortcuts: [AppShortcut] {
AppShortcut(
intent: CreateNewThing(),
phrases: [
"Create a new Thing in \(.applicationName)"
],
shortTitle: "Create a Thing",
systemImageName: "document.badge.plus"
)
AppShortcut(
intent: ThingAddDialog(),
phrases: ["Add Dialog in \(.applicationName)"],
shortTitle: "Add Thing Dialog",
systemImageName: "plus.square"
)
}//var
}//thing shortcuts
< /code>
Любое руководство будет оценено. XCODE 16.1, iOS 18.1
Подробнее здесь: https://stackoverflow.com/questions/792 ... ultiple-ne
Используйте Swift Appintents/ярлыки с SwiftData для Siri, чтобы запросить несколько новых полей записи. Сохранить запись ⇐ IOS
Программируем под IOS
1742006727
Anonymous
Я пытаюсь настроить ярлыки и аппараты, чтобы позволить пользователю вызвать Siri и открыть диалог для создания новой записи с двумя или более атрибутами модели SwiftData. Я успешно кодировал для Siri, чтобы открыть приложение и для того, чтобы Siri открыла приложение и перейти на страницу, чтобы добавить запись, но не смог захватить ответ пользователя из приглашения Siri и сохранить его в новые записи. Если это рассматривается в Apple Docs и примерах, я не смог его найти. < /P>
Вот что у меня есть: < /p>
@Model
class Thing {
var name: String = ""
var comment: String = "no comment"
var recordType: String = "0"
var count: Int = 0
init(name: String, comment: String, recordType: String, count: Int) {
self.name = name
self.comment = comment
self.recordType = recordType
self.count = count
}
}//class
struct CreateNewThing: AppIntent {
static var title: LocalizedStringResource = "Create New Thing"
static var description = IntentDescription("Opens the app and moves to the Add Thing screen.")
static var openAppWhenRun: Bool = true
@AppStorage("navigateToThingAddView") private var navigateToThingAddView: Bool = false
@MainActor
func perform() async throws -> some IntentResult {
navigateToThingAddView = true
return .result()
}
}//create new thing
struct ThingAddDialog: AppIntent {
static var title: LocalizedStringResource = "Add Thing Dialog"
static var description = IntentDescription("Prompt the user for a name and comment for a new Thing.")
static var openAppWhenRun: Bool = true
@Parameter(title: "Name", default: "")
var name: String
@Parameter(title: "Comment", default: "No comment")
var comment: String
@MainActor
func perform() async throws -> some ProvidesDialog & ShowsSnippetView {
// Logic to navigate to the Add Thing dialog view
//navigateToThingDialog = true
let dialog = IntentDialog(
full: "What is the name of the new Thing?",
supporting: "I have opened the Add Thing Dialog.")
let answer = $name.needsValueError("Provide a name")
name = answer.description
saveThing(name: name, comment: comment)
return .result(dialog: dialog)
}
@MainActor
private func saveThing(name: String, comment: String) {
let newThing = Thing(name: name, comment: comment, recordType: "0", count: 0)
// Add newThing to SwiftData
let container = try! ModelContainer(for: Thing.self)
container.mainContext.insert(newThing)
try? container.mainContext.save()
}
}
struct ThingShortcuts: AppShortcutsProvider {
static var shortcutTileColor = ShortcutTileColor.navy
static var appShortcuts: [AppShortcut] {
AppShortcut(
intent: CreateNewThing(),
phrases: [
"Create a new Thing in \(.applicationName)"
],
shortTitle: "Create a Thing",
systemImageName: "document.badge.plus"
)
AppShortcut(
intent: ThingAddDialog(),
phrases: ["Add Dialog in \(.applicationName)"],
shortTitle: "Add Thing Dialog",
systemImageName: "plus.square"
)
}//var
}//thing shortcuts
< /code>
Любое руководство будет оценено. XCODE 16.1, iOS 18.1
Подробнее здесь: [url]https://stackoverflow.com/questions/79276844/use-swift-appintents-shortcuts-with-swiftdata-for-siri-to-prompt-for-multiple-ne[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия