Search code examples
iosswifturl-scheme

Open a app within an app or if not already downloaded, got to app store (iOS)


I'm trying to have it setup to open an app from within the current app, if not go to the app store and download it. I know it involves URLSchemes, I did see this post: Launch App from within App

But it seems like they are referring to apps you already created. The app wanting to open is not my own app but a bike app: https://apps.apple.com/us/app/biketownpdx/id1132076989

I can access the url with:

if let url  = URL(string: https://apps.apple.com/us/app/biketownpdx/id1132076989)
        {
            if UIApplication.shared.canOpenURL(url)
            {
                UIApplication.shared.open(url)
            }
        }
    }

But am not completely sure how to open it if its already installed on my device.


Solution

  •    if UIApplication.shared.canOpenURL(other app scheme)
        {
             UIApplication.shared.open(other app scheme)
         }else {
             UIApplication.shared.open(AppStore url)
        }