In the Shortcuts app, there is an action called "Open App" (under the Scripting category). How can I run that in Swift?
I looked at AppIntents and SiriKit but just got way too confused, having a hard time figuring out the code.
In the Shortcuts app, there is an action called "Open App" (under the Scripting category). How can I run that in Swift?
I looked at AppIntents and SiriKit but just got way too confused, having a hard time figuring out the code.
This question, or very similar questions, have been answered before. The general gist of things is that you need to (for security reasons) pre-declare the URL(s) of the app(s) you want to launch from your app in your Info.plist file:
Then you'll be able to call uiapplication's openURL
function:
UIApplication.shared.openURL(URL(string: "someapp://")!, options: [:])
This should launch the app, although it may prompt the user with an alert to confirm that they want to launch it.
Other than that, there's really no way to do this for security and privacy reasons. You need to declare what apps you want to open because Apple found that some companies were using the openURL
API to determine if user's had certain apps installed, then using that to target ads to them. Plus, if any app could willy-nilly launch whatever process they wanted, that'd be a huge additional attack surface in the OS.
Important note: you should be able to launch certain system apps like Maps or Phone without needing to declare them in your Info.plist (e.g. tel:1005551000
will confirm that the user wants to call the number, then place the call).