I’ve tried implementing the newish shortcuts feature but the only scenario in which it works consistently for me is when my app isn’t running, eg if the user has force-quit the app or just restarted their phone.
If my app has already been run and is backgrounded, and the user long-presses on the app icon to invoke a shortcut, then the app is foregrounded but in order to display a MobileScreen to respond to the shortcut requires that I know the app’s current modal screen so that I can pass that as a parent property of the .ShowModal call otherwise the screen never appears. I have tried keeping track of the currently loaded modal screen but it seems complicated and error-prone as I need to make sure to expressly clear it each time.
So I’m wondering how others are using Shortcuts in their real-world apps?
Have you tried this?
Thanks Greg. That works to show the modal screen from the shortcut in all scenarios but also completely replaces the view hierarchy so obliterates everything underneath it which means that once a shortcut is launched, there’s nothing “left” of the app. Or am I doing it wrong?
So if you imagine an app with quite a few screens and the user can be happily working away in either a non-modal or modal screen in the app and then they background the app to do something else on their device. Later, with the app still backgrounded, they long-press on the app icon to invoke a shortcut. That shortcut needs to launch over the top of whatever the app is currently showing (modal or non-modal screen) and then, when the user taps the Done button on the shortcut screen, they can continue what they were doing before (ie they haven’t lost their former position in the app). I know I must be doing something wrong…
I wasn’t indicating that you’d set that property, just that you’d use the view in that value and show a modal over it.
Honestly most of the examples I’ve seen just change their tab view to the appropriate screen. Here’s an example of how you would do that:
Declare Function rootViewController Lib "UIKit" Selector "rootViewController" (obj As ptr) As ptr
Declare Function tabBar Lib "UIKit" selector "tabBar" (obj As ptr) As ptr
Declare Sub SetSelectedIndex Lib "UIKit" Selector "setSelectedIndex:" (obj As ptr, Assigns index As Integer)
Dim tabBar As Ptr = Self.CurrentLayout.Handle
Dim vc As ptr = rootViewController(tabBar)
SetSelectedIndex(vc) = idx // Index of the tab that you want to go to
I tried the switching tabs method already and it works fine if you don’t use modal screens but not if there is a modal screen visible when the user chooses to use a shortcut. You can see this for yourself with the iOS Mail app - tap the Compose button in the Mail app’s toolbar to create a new email, which launches as a modal, and then swipe up to background the app. Now long-press on the Mail app’s icon and choose either the Search or New Message shortcuts and you’ll see that a second modal screen is launched while preserving the modal screen that you’ve already launched for composing a message. I don’t expect to be able to have multiple screen support in Xojo like this but I’d like the second modal to launch on top of the first modal.
Your suggestion to use the view from
App.CurrentLayout.Content and do a ShowModal on top of it sounds like it would work for me and, sorry for the dumb question, but how do I get the view from that? I can only see how to get a ViewControllerHandle.