Launching the App Store from an iOS application


In this post we will learn how to open app store from iOS application.

In this example we will open app store and show Facebook app on store. You can open your app if you want just by changing the ID to your app id.

Lets do it.

Step 1 − Open Xcode → New Project → Single View Application → Let’s name it “OpenAppStore”

Step 2 − Open Main.storyboard and add a button as shown below.

Step 3 − Attach one @IBAction for the button for click event. Name the function as openAppstoreClicked.

Step 4 − In openAppstoreClicked we will write the code to open the app store. We will use openURL api to do so.

In the openAppstoreClicked method write following line of code

@IBAction func openAppstoreClicked(_ sender: Any) {
   if let url = URL(string: "https://itunes.apple.com/in/app/facebook/id284882215?mt=8") {
      UIApplication.shared.open(url, options: [:], completionHandler: nil)
   }
}

In the above code you can see we have passed the ‘facebook’ as app name and ID of the Facebook app. If you want, you can pass your app name and app ID. Then the button click will open app store with your app.

Step 4 − Run the app and click on ‘Open App Store’ button. The app store will be opened as shown in the picture below

Updated on: 11-Sep-2019

872 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements