How to know particular shortcut is added in our shortcuts app or not using our iOS app?

Viewed 661

I run the shortcuts with the x-callback url given below code:

let url = URL(string: "shortcuts://x-callback-url/run-shortcut?name=Airplane&x-success=shortcutsdemo://")
UIApplication.shared.open(url!, options: [:], completionHandler: nil)

When I open the URL in UIApplication.shared.open, it runs the shortcut and after its done, return back to our iOS app.

My question is if my shortcut is not added in shortcuts app, how I manage?

Is there any way to first find our shortcut is added or not in shortcuts app and then we run the shortcut.

Like :

if (Shortcut.isInstalled) {
    let url = URL(string: "shortcuts://x-callback-url/run-shortcut?name=Airplane&x-success=shortcutsdemo://")
    UIApplication.shared.open(url!, options: [:], completionHandler: nil)
} else {
   print("Not installed")
}    

Summary : If the shortcut is added in our shortcuts app, Then it's run the shortcuts using our iOS app. Otherwise its not run. and give an error for that shortcut.

1 Answers

I think you will need to use func canOpenURL(_ url: URL) -> Bool

let url = URL(string: "shortcuts://x-callback-url/run-shortcut?name=Airplane&x-success=shortcutsdemo://")

    if UIApplication.shared.canOpenURL(ur!l) {

        print("Short uts is installed")
    } else {

        print("Shortcuts not installed")
    }

I am not 100% sure, but I think it redirects you automatically to appstore if you don't have it, check that out.

Related