This guide describes the process of establishing the digital records and relationships necessary for a Unity game to interact with an In-App Purchase Store. The Unity IAPAbbreviation of Unity In App Purchase
See in Glossary purchasing API is targeted.
In-App Purchase (IAP) is the process of transacting money for digital goods. A platform’s Store allows purchase of Products, representing digital goods. These Products have an Identifier, typically of string datatype. Products have Types to represent their durability: subscription, consumable (capable of being rebought), and non-consumable (capable of being bought only once) are the most common.
Write a game implementing Unity IAP. Refer to Unity IAP Initialization.
Keep the game’s product identifiers on-hand for use in iTunes Connect later.
In the Apple Developer Center, navigate to the appropriate Identifiers section.
Add a new App ID to create a fundamental application entity with Apple.
NOTE: Use an Explicit App ID. You cannot use Wildcard App IDs (com.example.*) for applications that use In-App Purchases.
NOTE: The App ID is available to use in iTunes Connect after you create it in the Developer Center.
Navigate to iTunes Connect and create an App, to establish a Store relationship with your game.
Use the newly created App ID for the app’s Bundle ID.
Choose Features and add a new In-App Purchase with the plus (“+”) button.
Choose a Product Type.
Specify the Product Identifier, and complete other fields as requested.
Note: The “Product ID” here is the same identifier used in the game source code, added to the Unity IAP ConfigurationBuilder instance by using AddProduct() or AddProducts().
Note: When targeting multiple Apple device groups (for example, shipping on both iOS and Mac) Apple requires usage of different, unique product identifiers for each distinct device group. Use Unity IAP’s Purchasing.IDs class and define a one-to-many mapping Product IDs to the store-specific identifiers, and pass that mapping in when initializing IAP.
Result:
Create Sandbox Testers using iTunes Connect for use on your test device’s iTunes Account. To do this, go to iTunes Connect > Users and Roles, and choose the plus (“+”) button. You must review Apple’s Sandbox Tester documentation as there are several additional important usage notes, and you must use a real email address to create Testers.
Note: For more information, refer to the iOS and Mac App Store guides.
Tip: To simplify managing the email address, use an email service capable of sub-addressing (emailaccount+subaddress@example.com) such as Gmail, iCloud, and Outlook.com. This allows one email account to receive email for multiple sub-addresses.
Complete the user creation wizard.
Build the Xcode project for your game by using Unity.
Note: Ensure the Bundle Identifier in Unity (Edit > Project Settings, then select the Other Settings category, and navigate to the Bundle Identifier section) matches that used in iTunes Connect.
In your game’s Xcode project, ensure the Team (Project Navigator > your game Target > General > Identity > Team) is set to that of your Apple Developer account.
Using the target iOS device, sign out of any existing Apple ID accounts. Only sign in as the Sandbox Tester when prompted by the app, later. Any subsequent purchases are routed through the Apple Sandbox instead of the Production Store.
Build and run the game on your iOS device. UnityPurchasing.Initialize()
succeeds if everything has been correctly configured.
Test the IAP by making a purchase in the game on the device. A modified purchase dialog displays, explaining that this purchase is being performed in the Sandbox Environment. Use the Sandbox User Tester password when prompted for purchase.
Warning: If the indicator is not present, then an account is charged real money for the product.
When building a desktop Mac build, select Mac App Store Validation within Unity’s Mac Player settings.
After you have built your App, update its info.plist
file with your bundle identifier and version strings. Right-click the .app file and select Show Package Contents, locate the info.plist
file and update the CFBundleIdentifier
string to your application’s bundle identifier.
Sign, package, and install your application. Run the following commands from an OSX terminal, filling in “your.app” and “your.pkg” appropriately.
Tip: To sign the bundle, you might first need to remove the Contents.meta file if it exists: your.app/Contents/Plugins/unitypurchasing.bundle/Contents.meta
codesign -f --deep -s "3rd Party Mac Developer Application: " your.app/Contents/Plugins/unitypurchasing.bundle
codesign -f --deep -s "3rd Party Mac Developer Application: " your.app
productbuild --component your.app /Applications --sign "3rd Party Mac Developer Installer: " your.pkg
To install the package correctly, delete the unpackaged .app file before you run the newly created package and install it.
Launch the app from the Applications folder. The first time you do so, you are prompted to enter your iTunes account details, for which you can then make test purchases against the sandbox environment.
For more information on Apple App Store testing and signing, refer to iOS and Mac Extended Functionality and Building your macOS application.
When you visit any website, it may store or retrieve information on your browser, mostly in the form of cookies. This information might be about you, your preferences or your device and is mostly used to make the site work as you expect it to. The information does not usually directly identify you, but it can give you a more personalized web experience. Because we respect your right to privacy, you can choose not to allow some types of cookies. Click on the different category headings to find out more and change our default settings. However, blocking some types of cookies may impact your experience of the site and the services we are able to offer.
More information
These cookies enable the website to provide enhanced functionality and personalisation. They may be set by us or by third party providers whose services we have added to our pages. If you do not allow these cookies then some or all of these services may not function properly.
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us to know which pages are the most and least popular and see how visitors move around the site. All information these cookies collect is aggregated and therefore anonymous. If you do not allow these cookies we will not know when you have visited our site, and will not be able to monitor its performance.
These cookies may be set through our site by our advertising partners. They may be used by those companies to build a profile of your interests and show you relevant adverts on other sites. They do not store directly personal information, but are based on uniquely identifying your browser and internet device. If you do not allow these cookies, you will experience less targeted advertising. Some 3rd party video providers do not allow video views without targeting cookies. If you are experiencing difficulty viewing a video, you will need to set your cookie preferences for targeting to yes if you wish to view videos from these providers. Unity does not control this.
These cookies are necessary for the website to function and cannot be switched off in our systems. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms. You can set your browser to block or alert you about these cookies, but some parts of the site will not then work. These cookies do not store any personally identifiable information.