- iOS 11.0+
- Xcode 10.1+
This sample code project shows how to make it possible for users to purchase media from your app using the
SKStore class. Additionally, the sample demonstrates how to measure the effectiveness of a cross-promotional campaign for your apps or third-party apps using
The app in this sample project displays a list of media items that the user can tap in order to make purchases from the App Store. You can also track advertising and promotions from this interactive list of media items for sale.
You must run this sample on an iOS device.
This sample defines a
Product data type to represent media information saved in the
Products contains a single
Product entry. Before you can run this sample on your device, you must update this entry with your own data.
Set the sample’s
productkey to your media’s iTunes identfier. For more information on how to get iTunes identifiers, see
Product Parameter ITunes Item Identifier
titlekey to your media’s name.
iskey to YES if your media is an app and NO otherwise.
providerkeys to the appropriate tokens if you are cross-promoting apps and leave them empty if you are not. For more information on how to generate campaign and provider tokens, see
Measure campaign performance,
Campaign Token, and
To test more data, duplicate and update the
Product entry in
Products as needed.
Display Media from the App Store
This sample launches to the
Table view controller that shows a list of media associated with iTunes identifiers saved in
Products. When the user taps any item in the list,
Table presents a page where they can purchase the media from the App Store. Use the following steps to set up the media list.
First, you must create a parameters dictionary with a
SKStore key set to your media’s iTunes identifier (see
SKStore for more information on how to find iTunes identifiers):
Then create an
SKStore object and set the view controller class as its delegate. Next, pass the dictionary to the
load method of the
Finally, present the
SKStore object modally from your app:
The delegate must dismiss the store view controller once the purchase completes or is canceled.
Table implements the
SKStore method to dismiss the presented store product view controller. In your app, you can also use this method to resume any activities that were paused before presenting the store.
Track Advertising and Promotions
SKStore keys allow you to track advertising and promotion for an app. When a user taps
Find My Friends (with App Analytics campaign) in the list,
Table adds these keys and their values to a dictionary, which already contains
SKStore set to its iTunes identifier.
When cross-promoting your apps, set
SKStore to your own provider token. When promoting apps for other developers, set it to their provider token.
Table passes the dictionary to a created
SKStore object, then proceeds to display the store product view controller modally, as discussed in the section Display Media from the App Store: