Contents

Testing Ask to Buy in Xcode

Validate your app’s handling of Ask To Buy in the testing environment.

Overview

With Ask to Buy, when a child wants to make an eligible purchase or download, the system sends the purchase request to the parent or guardian. For more information, see Approve what kids buy with Ask to Buy.

You can test approving and declining Ask to Buy purchases in the Xcode testing environment. Use the StoreKit configuration file to set up and control the test case.

Perform basic setup

Before you can begin testing in Xcode, complete the steps in Setting up StoreKit Testing in Xcode, to create a StoreKit configuration file and enable StoreKit testing in Xcode.

Enable Ask to Buy for testing

Open the StoreKit configuration editor in Xcode and define at least one in-app purchase. Then follow these steps in the StoreKit configuration editor:

  1. In the left pane, select Configuration Settings.

  2. Under the Purchase Options heading in the editor, enable Ask to Buy.

Test approving a purchase

To test approving a purchase, run your app in the Xcode environment and follow these steps:

  1. In your app, attempt to purchase the in-app purchase.

  2. When the Ask Permission dialog appears, select Ask.

  3. In the Xcode StoreKit transaction manager, notice that the Pending Approval purchase appears with a state of Pending Ask to Buy. In your code, verify the purchase state is Product.PurchaseResult.pending.

  4. Control-click the transaction and select Approve.

  5. In the Xcode StoreKit transaction manager, verify that the state is now Ask to Buy Approved. In your code, verify the purchase state is Product.PurchaseResult.success(_:).

  6. Check that the app unlocks the content and finishes the transaction.

Test declining a purchase

To test declining a purchase, run your app in the Xcode environment and follow these steps:

  1. In your app, attempt to purchase the in-app purchase.

  2. When the Ask Permission dialog appears, select Ask.

  3. In the Xcode StoreKit transaction manager, notice that the Pending Approval purchase appears with a state of Pending Ask to Buy. In your code, verify the purchase state is Product.PurchaseResult.pending.

  4. Control-click the transaction and select Decline.

  5. In the Xcode StoreKit transaction manager, verify that the state is now Ask to Buy Declined. Your app doesn’t receive a transaction because you declined Ask to Buy.

For more information about using the transaction manager, see Testing in-app purchases with StoreKit transaction manager in Xcode.

Reset or rerun the test

You can run the same test again without resetting state values. When you’re done, turn off Ask to Buy to prevent it from affecting future tests.

See Also

In-App Purchase Testing