An easy way to open the AppStore within your app
Using SKStoreProductViewController from Apple
Similar to SFSafariViewController, SKStoreProductViewController
opens a modal that will allow your user to interact with a product in the App Store without leaving your app.
Usage
You need a few things:
- Import
StoreKit
- Create an
SKStoreProductViewController
instance and set itsdelegate
- Indicate a specific product by passing its iTunes item identifier to the
loadProduct(withParameters:completionBlock:)
method. - A simple implementation of
SKStoreProductViewController
delegate
Implementation
Let's assume you have a view controller from which you want to show the SKStoreProductViewController
. We are going to exemplify that with the following code:
The intention would be to call openAppStore()
after an user interaction, such as tapping a button.
The result should be something like this:
Limitations
- The
SKStoreProductViewController
class doesn’t support subclassing or embedding, and must be used as-is. - Will Thrown
SKUnsupportedPresentationException
if the app attempts to use an unsupported presentation mode forSKStoreProductViewController
, such as embedding it as a child view controller or attempting to use it in a popover.
Conclusion
When we are in the need to open or display external resources such as a URL or PDF or an App Store product, I consider it imperative to show that within your app. Keeping the user in your ecosystem is a much better experience than making them jump between apps. In general, makes the user experience of your app more immersive and makes your app flows more fluid and with fewer interruptions.
Source
Every great developer you know got there by solving problems they were unqualified to solve until they actually did it.
— Patrick McKenzie
Thanks for reading and hope you find this article helpful. As usual, any feedback or comment is welcome.