Promoted In-App Purchase trong iOS

Tram Ho


Starting with iOS 11, Apple offers Promote in-app purchase on the App Store. This means that in-app purchase items, instead of being purchased within the app, can also be "promoted" on the product page on the App Store.

Users can choose to purchase items directly, subcribe the subscriptions, and navigate to the payment interface within the app. Users will be asked to download and install the app if it is not already installed.

Promote in-app purchase requires 2 basic steps:

  • Upload photos for the items, subscription in-app purchase that you want to display on App Store Connect. We can use the App Store Promotions tool in App Store Connect to manage and change their order when appearing on the App Store.
  • Implement delegate method of SKPaymentTransactionObserver protocol to handle purchases.

Guildline for marketing in-app purchases on the App Store can be found at Promoting Your In-App Purchases .

To customize the list of promoted in-app purchases, we can use SKProductStorePromotionController to override the App Store Connect default settings such as hiding, showing and order of items. These override settings are separate for each device and they are not synchronized with the iCloud account. Note that this advanced feature depends on the device memory capacity and its API only works after the app has been started at least once. It is not required to implement SKProductStorePromotionController to promote in-app purchases to the App Store.

Complete a Purchase

When a user chooses to purchase an in-app purchase item on the App Store, StoreKit will automatically open your app and send transaction information via the SKPaymentTransactionObserver protocol delegate methods. Our job is to continue the purchase transaction and complete the rest of the transaction. For example: authentication, coin addition, unlock level, item …

In the delegate method, return true to continue the transaction, return false to suspend or cancel the transaction.

If the app has not been installed, then when tapping on the in-app purchase item, the App Store will automatically ask the user to download and install it (if the app costs money, it will require a purchase). If the app is already installed but the current version of the app is not yet available for this promotion in-app purchase, the App Store will ask the user to upgrade the app to the latest version.

Continue a Transaction

To continue an in-app purchase transaction, we only need to implement the paymentQueue(_:shouldAddStorePayment:for:) delegate method paymentQueue(_:shouldAddStorePayment:for:) of the SKPaymentTransactionObserver protocol and return true . StoreKit will display the payment page and then the user can complete the normal transaction like a traditional in-app purchase.

Defer or Cancel a Transaction

If you need to suspend or cancel the transaction, return false . For example, when we cannot connect to the server of the app (unable to authenticate transactions, service unavailable …), we need to postpone this transaction and continue when the server is operational. Or when the user has already unlocked the item, already subscribed to that subscription, then the transaction needs to be canceled.

To postpone a transaction:

  1. Save the payment you need to pause to continue when the app is ready. SKPayment contains information about products, cannot create new SKPayment instance.
  2. Return false .
  3. After completing the transaction, add the saved payment back to the payment queue to continue the transaction as usual.

To cancel a transaction:

  1. Return false .
  2. Give feedback, notify the user. Although this step is not mandatory, if not inform the user, your app will lack action, not responding after the user tap on in-app purchase in the App Store. This looks like a bug, which will make the user experience not good.

Visibility Settings

Get Visibility Settings

To get visibility settings for a product, use the fetchStorePromotionVisibility(for:completionHandler:) and pass in the product information.

Override Visibility Settings

For each different device, we can decide when the in-app purchase item is hidden or visible. For example, you want to hide items that a user has purchased and show only items that they can currently buy.

To do this, first, fetch the product info and update the default store promotion controller with the .hide setting, as shown below. This product will no longer appear on the App Store for this device.

In this example, visibility is set by .default to .default . Whether the product is hidden or currently based on the default setting you have set on the App Store Connect.

Order of Promoted Products

Override the Order of Promoted Products

Similar to visibility settings, for each different device, we can also change the display order of promoted in-app purchase items on the App Store. For example, in your game app, the user has passed level 10, you can change the order, bring the level's items to the top of the list so that the user can easily see and buy them.

To override the default product order, initialize the array of products in the order you want and pass the update(storePromotionOrder:completionHandler:) method update(storePromotionOrder:completionHandler:) . The products in this array will appear in the correct order at the top of the list, followed by the rest of the products you have set in the App Store Connect.

Cancel Order Overrides

To cancel custom orders, we simply need to pass an empty array to the update(storePromotionOrder:completionHandler:) method update(storePromotionOrder:completionHandler:) . The in-app purchase item list will be displayed in the default order.

Fetch Order Overrides

To get the product order of the current device, use the fetchStorePromotionOrder(completionHandler:) method. We will get an array of products in the current order. If this method returns an empty array, this means that the products are being displayed in the default order.

Source article: Promoting In-App Purchases

Share the news now

Source : Viblo