Если условие не выполняется, я представляю, что поток будет выглядеть так:< /p>
- Откройте приложение A.
- Вместо этого откроется мое приложение B.
- I установите флажок в моем приложении B.
- Я возвращаюсь к приложению A, и оно работает как ожидается.
< strong>Что мы пробовали до сих пор
Моя первая попытка заключалась в использовании AppIntent и программном изменении openAppWhenRun в зависимости от условия. Однако я довольно быстро понял, что изменение значения openAppWhenRun не изменится, если AppIntent действительно откроет мое приложение. Код для этого выглядел так: значение openAppWhenRun изменяется в другой функции.
Код: Выделить всё
struct BlockerIntent: AppIntent {
static let title: LocalizedStringResource = "Blocker App"
static let description: LocalizedStringResource = "Blocks an app until condition is met"
static var openAppWhenRun: Bool = false
@MainActor
func perform() async throws -> some IntentResult {
return .result()
}
}
Код: Выделить всё
struct BlockerIntent: AppIntent {
static let title: LocalizedStringResource = "Blocker App"
static let description: LocalizedStringResource = "Blocks an app until condition is met"
static var openAppWhenRun: Bool = false
func perform() async throws -> some IntentResult & OpensIntent {
if (BlockerIntent.openAppWhenRun) {
throw Error.notFound
}
return .result(opensIntent: OpenBlockerApp())
}
enum Error: Swift.Error, CustomLocalizedStringResourceConvertible {
case notFound
var localizedStringResource: LocalizedStringResource {
switch self {
case .notFound: return "Ignore this message"
}
}
}
}
struct OpenBlockerApp: AppIntent {
static let title: LocalizedStringResource = "Open Blocker App"
static let description: LocalizedStringResource = "Opens Blocker App"
static var openAppWhenRun: Bool = true
@MainActor
func perform() async throws -> some IntentResult {
return .result()
}
}
Код: Выделить всё
struct BlockerIntent: AppIntent {
static let title: LocalizedStringResource = "Blocker App"
static let description: LocalizedStringResource = "Blacks an app until condition is met"
static var openAppWhenRun: Bool = false
func perform() async throws -> some IntentResult & OpensIntent {
if (BlockerIntent.openAppWhenRun) {
return .result(opensIntent: DoNotOpenBlockerApp())
} else {
return .result(opensIntent: OpenBlockerApp())
}
}
}
Код: Выделить всё
Function declares an opaque return type 'some IntentResult & OpensIntent', but the return statements in its body do not have matching underlying types
Есть ли какой-нибудь способ сделать то, что я пытаюсь сделать? Я видел другие приложения, использующие подобную концепцию, поэтому считаю, что это возможно.
Большое спасибо!
Подробнее здесь: https://stackoverflow.com/questions/774 ... -shortcuts