Objective: When the app is running, directly operate the app without launching it. When the app is not started, wake up the app to perform the corresponding operation.
Premise: AppIntent's openAppWhenRun can dynamically control whether the app is launched, but the variable itself cannot be changed.
Therefore, the idea is to refresh the widget when the app is started or terminated, displaying different content (binding different intents) to achieve the goal.
However, there are persistent issues during code implementation.
struct ControlWidgetContent: ControlWidgetTemplate {
var body: some ControlWidgetTemplate {
if (applaunched) {
return ControlWidgetButton(action: Aintent()) {
Label("xxxx", systemImage: "calendar")
}
} else {
return ControlWidgetButton(action: Bintent()) {
Label("xxxx", systemImage: "calendar")
}
}
}
}
@available(iOS 18.0, *)
struct ControlWidgetContent: ControlWidget {
let kind: String = "ControlWidgetInterface"
var body: some ControlWidgetConfiguration {
StaticControlConfiguration(
kind: kind
) {
ControlWidgetContent()
}.displayName("xxxx")
}
}
it preports error:
Function declares an opaque return type 'some ControlWidgetTemplate', but the return statements in its body do not have matching underlying types
Return statement has underlying type 'ControlWidgetButton<Label<Text, Image>, ControlWidgetButtonDefaultActionLabel, PlayDayRcmdIntent>'