Using In-App Purchases on iOS

Using in-app purchases to offer additional paid content for your iOS game.

Choose your operating system:

Windows

macOS

Linux

Configuration

  1. Set up your in-app purchase in iTunes Connect:

    Google Play requires the id to be all lowercase, and it's best to have the ID for iOS and Android match for ease of Blueprint setup.

    image alt text

  2. Make a note of the ID you use, as well as if the item is consumable or non-consumable.

  3. If you have a Blueprint project, you're set to go. If you have a code project and have not already set up your project to use online subsystems, add the following block to your project's Build.cs file:

    if (Target.Platform == UnrealTargetPlatform.IOS)
    {
        PrivateDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "OnlineSubsystem" });
        DynamicallyLoadedModuleNames.Add("OnlineSubsystemIOS");
    }
  4. Edit [ProjectName]/Config/IOS/IOSEngine.ini:

    [OnlineSubsystemIOS.Store]
    bSupportsInAppPurchasing=True

Reading Purchase Information

image alt text

You can read the in-app purchase information using the Read In-App Purchase Information Blueprint node (or associated C++ function call). Like most other online subsystems functions, it takes a Player Controller as input, as well as an array of your product identifiers. Note that Make In-App Purchase below takes a single identifier, while Read can process an array of information. The function returns an array of In App Purchase structs, and each element of the array can be broken out to get the name, description, price, and other data to display in your UI or use in your gameplay logic.

Completing a Purchase

image alt text

To make an in-app purchase, use the Make an In-App Purchase Blueprint node (or associated C++ function call). It takes the Player Controller as input, as well as a Product Request struct. A Product Request is just the product identifier from iTunes Connect or the Google Play Developer console (in this case, match3theme_night), as well as whether or not the product is consumable.

The Make an In-App Purchase node is latent, so any gameplay behavior you want to have rely on whether the purchase succeeds or fails should use those two execution pins. They will only execute after a response has come back from the online service. The node also returns the completion status of the purchase (such as Success, Failed, Restored) and the detailed In App Purchase Information struct.

There is a non-latent version of this function (the Blueprint node will display without the clock). The exit execution pin here does not wait for a response from the online service, and you will generally want to use the latent version.

Restoring Purchases

image alt text

To restore purchases, use the Restore In-App Purchases Blueprint node (or associated C++ function call). It only takes in the Player Controller, and returns an array of all the purchase information associated with that Player Controller. You can then process that array to compare against the particular Identifier (or Identifiers) that your gameplay logic needs.

Testing

You can test with a build that you load onto the device yourself, as well as with a build uploaded to iTunes Connect. Any users testing the purchase must be Internal or External Testers in iTunes Connect, and must have accepted that invitation. You'll also need your custom provision.

Help shape the future of Unreal Engine documentation! Tell us how we're doing so we can serve you better.
Take our survey
Dismiss