Set openAppWhenRun variable in AppIntent programatically.

I need to set the openAppWhenRun:Bool dynamically in App Intent. Eventhough I set this way. the app does not open when run the shortcut automation.

static var openAppWhenRun:Bool { myNumber == 4 ? true : false }

Post not yet marked as solved Up vote post of Yodagama Down vote post of Yodagama
2.0k views
  • static var openAppWhenRun:Bool { myNumber == 4 }

Add a Comment

Replies

As far as I can see openAppWhenRun is static, and is read and opens the app even before perform() is run (if openAppWhenRun is true that is). In other words, openAppWhenRun can not be dynamic. Your variable myNumber is always false at the time the App Intent is run so that is why your app never opens.

It would be interesting to see where you set, and changed, the myNumber variable.

  • Hi @skyapp thanks for the reply. myNumber is a global variable.

    This is what I need to be done. User can change this from a view.

  • You can't dynamically set openAppWhenRun. You need to create a new AppIntent with openAppWhenRun = true, and call it from you existing AppIntent using return .result(openIntent: NewAppletName()). The Dive into App Intents video has an example of this. https://developer.apple.com/videos/play/wwdc2022/10032/ at 17:19.

Add a Comment

You can't dynamically set openAppWhenRun. You need to create a new AppIntent with openAppWhenRun = true, and call it from you existing AppIntent using return .result(openIntent: NewAppletName()). The Dive into App Intents video has an example of this. at 17:19. 

Add a Comment

Hello @Yodagama . I was curious how you implemented this.I have an HomeIntent whose openAppWhenRun value is false.Now i made another intent called OpenApp whose openAppWhenRun value is true.I returned this in perform function return .result(opensIntent: OpenApp() ).But still it does not solve the issue of imitating the dynamic value of showing the app in some cases and not showing in some as the other intent's open value remains always true.Any help regarding this is appreciated 😇

It appears there's a solution to a problem, but I've yet to find it. The One-Sec App seems to utilize precisely what is described here. Currently, I've implemented the suggested solution, which technically works by throwing an error, but it's not ideal as it could be irritating for users to encounter it repeatedly.

I've experimented with various methods, but nothing is working as intended: on one hand, it seems impossible to eliminate the error when attempting to use two different intents without throwing an error due to the mismatch in underlying types, and on the other hand, you can't catch the error to prevent the user from seeing it.

It's clear there must be a solution to this problem, but I've been unable to discover it. Any guidance or insights would be greatly appreciated.