Time for action – Adding In-App purchases

  1. The first step in defining In-App purchases is to add the purchase types to the application in iTunes Connect. On the application profile page, select the Manage In-App Purchases link in the portal:
    Time for action – Adding In-App purchases
  2. On the In-App Purchases screen select Create New to start the process:
    Time for action – Adding In-App purchases
  3. Next we want to set up an In-App purchase that represents a new gun type for the user, so select Non-Consumable:
    Time for action – Adding In-App purchases
  4. In the details area provide a Reference Name and a Product ID for the product. The Product ID is what you will use to refer to the product in the Store Kit APIs later. You can call your product ID whatever you want, it is for your own internal purposes. You should follow the naming convention you used for your product to ensure that you will not have any name collisions between products, versions, and so on:
    Time for action – Adding In-App purchases
  5. As iOS applications and iTunes support localization you need to set the language for how your product will be displayed in the store. Select Add Language and enter the store details for the product.
    Time for action – Adding In-App purchases
  6. Next set the pricing for the product. The tiers for In-App Purchases are similar to those of regular iTunes App Store purchases:
    Time for action – Adding In-App purchases
  7. Next we need to add a screenshot for the App Store review team. It's not entirely clear how this screenshot is used, but you will not be able to submit your In-App purchase without this 320x240 image:
    Time for action – Adding In-App purchases
  8. With this update completed, review the In-App purchase list to ensure that the details entered match what is submitted for your game:

    Note

    The purchase is currently pending review.

    Time for action – Adding In-App purchases

    With this completed we can write the plugin code necessary to access this In-App purchase within our Unity game.

  9. Drag the StoreKitManager prefab from the Prime31 Plugin into the scene. The StoreKitManager is responsible for communicating with the native Objective-C libraries on the iOS device to handle integration with the Apple StoreKit API.
  10. Drag the StoreKitEventListener prefab into the scene. As StoreKit events happen on the iOS device, the StoreKitEventListener will receive notifications about them from the operating system.
  11. To keep things simple we will create a simple GUI Button that when clicked will cause the user to purchase the BFG weapon.
  12. Create a new script called InAppPurchases:
    using UnityEngine;
    using System.Collections.Generic;
    
    public class InAppPurchases : MonoBehaviour
    {
    #if UNITY_IPHONE
      void OnGUI()
      {
        if( GUI.Button( new Rect( 0, 0, 50, 40 ), "Purchase BFG" ) )
        {
          bool canMakePayments = StoreKitBinding.canMakePayments();
    
          if ( canMakePayments )
          {
            StoreKitBinding.purchaseProduct( "bfg_001", 1 );
    
          }
        }
    #endif
    }

What just happened?

We have just created our second channel of revenue, In-App purchases. We have just created a mechanism through which the user can purchase the BFG weapon for use in the game by pressing a button on the game interface.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.191.218.84