I am currently creating an App
which is supposed to launch via an AppIntent. For example whenever I open Instagram it should trigger the AppIntent, which then decides if my App is supposed to open or not. The first part already works fine via Apple Shortcuts.
The problem is dynamically opening or not opening my App
. Unfortunately the openAppWhenRun field is supposed to be static and cannot be computed at runtime.
Here is the AppIntent so far:
struct OpenTimeEfficientIntent: AppIntent {
static var title: LocalizedStringResource = "Opens the app conditionally"
static var openAppWhenRun: Bool = false
@Parameter(title: "OpenedApp", optionsProvider: Provider())
var app: String //this is the initially opened app e.g. Instagram (i want to pass it)
@MainActor
func perform() async throws -> some IntentResult & ProvidesDialog {
//at this point I want to decide, whether the app should be launched or not
}
}
Just to specify: I don't want to decide which view I want to open but rather if I want to open the App
at all.
What did I try?
I already tried to open the app via Deeplinks which is not allowed on iOS as the AppIntent is just a background task: The App is neither visible nor entitled, so may not perform un-trusted user actions
Trying to set the openAppWhenRun
dynamically didn't work either.
For context
The app is basically a confirmation dialog. When I press no, the app closes and nothing happens. When I press yes, Instagram would be opened again. But in that case I don't want to launch my app again to prevent being stuck in a loop.