|
| 1 | +# In App Purchase iOS Example |
| 2 | + |
| 3 | +Demonstrates how to use the In App Purchase iOS (IAP) Plugin. |
| 4 | + |
| 5 | +## Getting Started |
| 6 | + |
| 7 | +### Preparation |
| 8 | + |
| 9 | +There's a significant amount of setup required for testing in app purchases |
| 10 | +successfully, including registering new app IDs and store entries to use for |
| 11 | +testing in App Store Connect. The App Store requires developers to configure |
| 12 | +an app with in-app items for purchase to call their in-app-purchase APIs. |
| 13 | +The App Store has extensive documentation on how to do this, and we've also |
| 14 | +included a high level guide below. |
| 15 | + |
| 16 | +* [In-App Purchase (App Store)](https://developer.apple.com/in-app-purchase/) |
| 17 | + |
| 18 | +### iOS |
| 19 | + |
| 20 | +When using Xcode 12 and iOS 14 or higher you can run the example in the simulator or on a device without |
| 21 | +having to configure an App in App Store Connect. The example app is set up to use StoreKit Testing configured |
| 22 | +in the `example/ios/Runner/Configuration.storekit` file (as documented in the article [Setting Up StoreKit Testing in Xcode](https://developer.apple.com/documentation/xcode/setting_up_storekit_testing_in_xcode?language=objc)). |
| 23 | +To run the application take the following steps (note that it will only work when running from Xcode): |
| 24 | + |
| 25 | +1. Open the example app with Xcode, `File > Open File` `example/ios/Runner.xcworkspace`; |
| 26 | + |
| 27 | +2. Within Xcode edit the current scheme, `Product > Scheme > Edit Scheme...` (or press `Command + Shift + ,`); |
| 28 | + |
| 29 | +3. Enable StoreKit testing: |
| 30 | + a. Select the `Run` action; |
| 31 | + b. Click `Options` in the action settings; |
| 32 | + c. Select the `Configuration.storekit` for the StoreKit Configuration option. |
| 33 | + |
| 34 | +4. Click the `Close` button to close the scheme editor; |
| 35 | + |
| 36 | +5. Select the device you want to run the example App on; |
| 37 | + |
| 38 | +6. Run the application using `Product > Run` (or hit the run button). |
| 39 | + |
| 40 | +When testing on pre-iOS 14 you can't run the example app on a simulator and you will need to configure an app in App Store Connect. You can do so by following the steps below: |
| 41 | + |
| 42 | +1. Follow ["Workflow for configuring in-app |
| 43 | + purchases"](https://help.apple.com/app-store-connect/#/devb57be10e7), a |
| 44 | + detailed guide on all the steps needed to enable IAPs for an app. Complete |
| 45 | + steps 1 ("Sign a Paid Applications Agreement") and 2 ("Configure in-app |
| 46 | + purchases"). |
| 47 | + |
| 48 | + For step #2, "Configure in-app purchases in App Store Connect," you'll want |
| 49 | + to create the following products: |
| 50 | + |
| 51 | + - A consumable with product ID `consumable` |
| 52 | + - An upgrade with product ID `upgrade` |
| 53 | + - An auto-renewing subscription with product ID `subscription_silver` |
| 54 | + - An non-renewing subscription with product ID `subscription_gold` |
| 55 | + |
| 56 | +2. In XCode, `File > Open File` `example/ios/Runner.xcworkspace`. Update the |
| 57 | + Bundle ID to match the Bundle ID of the app created in step #1. |
| 58 | + |
| 59 | +3. [Create a Sandbox tester |
| 60 | + account](https://help.apple.com/app-store-connect/#/dev8b997bee1) to test the |
| 61 | + in-app purchases with. |
| 62 | + |
| 63 | +4. Use `flutter run` to install the app and test it. Note that you need to test |
| 64 | + it on a real device instead of a simulator. Next click on one of the products |
| 65 | + in the example App, this enables the "SANDBOX ACCOUNT" section in the iOS |
| 66 | + settings. You will now be asked to sign in with your sandbox test account to |
| 67 | + complete the purchase (no worries you won't be charged). If for some reason |
| 68 | + you aren't asked to sign-in or the wrong user is listed, go into the iOS |
| 69 | + settings ("Settings" -> "App Store" -> "SANDBOX ACCOUNT") and update your |
| 70 | + sandbox account from there. This procedure is explained in great detail in |
| 71 | + the [Testing In-App Purchases with Sandbox](https://developer.apple.com/documentation/storekit/in-app_purchase/testing_in-app_purchases_with_sandbox?language=objc) article. |
| 72 | + |
| 73 | + |
| 74 | +**Important:** signing into any production service (including iTunes!) with the |
| 75 | +sandbox test account will permanently invalidate it. |
0 commit comments