This is an old revision of the document!
—-
Starting with iOS 3.0, the users can purchase "products" directly from applications. This technology is called "in app purchases". These products can be of three types:
WME Lite supports purchases of non-consumable products.
All products must be defined in the iTunes Connect interface to be available. Follow the instructions outlined in Apple documentation.
A few important notes:
* After you define products in iTunes Connect it takes some time before they are accessible to your app. * In app purchases must be tested on the actual device. They don't work in iOS simulator. * For testing, create test user in iTunes Connect, don't use your primary Apple ID.
WME Lite provides a scripting interface for in app purchases via a Store object. Store object is accessed via Game.Store property. It is recommended that you put the Store object to a separate variable for convenience:
var Store = Game.Store;
The game should always first check whether the store is available. The users can disable in app purchases in the iPhone Settings (Settings → General → Restrictions → In-App Purchases). If the store is not available, notify the user and don't let them purchase products.
if (!Store.Available) { // notify user }
As stated above, all the available products must be defined in iTunes Connect first. Each product has a unique ID (for example "org.deadcode.wmelite.unlock").
The game must know which IDs it's going to use. But before they can be purchased, the game must ask the App Store whether the products are available. This is done using the Store.ValidateProducts() method.
Store.ValidateProducts("org.deadcode.wmelite.unlock");
If you need to validate multiple IDs, separate them with semicolon:
Store.ValidateProducts("product1;product2;product3");
This method is asynchronous. Meaning it takes a while before the product IDs are validated (the game must connect to App Store via network). Once the products are validated, the script receives a "ProductsValidated" event. Since the validation takes time, you may want to display some waiting animation. Also always provide some kind of "cancel" button.
// display waiting animation // and a "cancel" button // ... // invoke validation Store.ValidateProducts("org.deadcode.wmelite.unlock"); on "ProductsValidated" { // products are now validated, display purchase GUI } // assuming your cancel button is called "cancel"... on "cancel" { // cancel the process (close the purchase window etc.) }
Once the products are validated, you can query which ones are avaiable, and which IDs are invalid.
// list invalid product IDs for (var i = 0; i < Store.NumInvalidProducts; i = i + 1) { Game.Msg(Store.GetInvalidProduct(i)); }
In case of valid products you can access the name, description and price of the products. Use this info to offer the products to the user. This information is localized, based on the user's App Store country (you can fill localized descriptions in iTunes Connect).
// list valid products for (var i = 0; i < Store.NumValidProducts; i = i + 1) { var product = Store.GetValidProduct(i); Game.Msg("ID: " + product.Id + " Name: " + product.Name + " Description: " + product.Description + " Price: " + product.Price); }