StoreKit Initialization

After you filled up all your app in-game products with iTunesConnect, as was shown in the previous article,  you can now implement it in your game.

Enabling StoreKit

Before you begin, you need to enable StoreKit framework and add the same in-app purchases that you have inside iTunes Connect console. with IOS Native editor settings window. You can bring up this window using main menu command:

Stan's Assets -> IOS Native -> Settings

Note: As you may notice you can fill in some initial product info. But as soon as products data delivered from Apple Server after you complete initialization process. That data will be overridden.

Ther is just a few things you should know:

  • Apple does not provide an image to a product, so we added that filed just for your connivance.
  • Pirce Tires you see is only an editor filed. Do not use it runtime.
  • Feel free to use any property of ISN_SKProduct once initialization is done.

Connecting to Payment Server

Before you can start any purchase flow, you need to connect to the Apple Payment server. Also keep in mind, that an iPhone can be restricted from accessing the Apple App Store. For example, parents can restrict their children’s ability to purchase additional content. Your application should confirm that the user is allowed to authorize payments before adding a payment to the queue. Your application may also want to alter its behavior or appearance when the user is not allowed to authorize payments. You can check if a user is allowed to make payments with the CanMakePayments property.

using SA.IOSNative.StoreKit;
...
bool canMakePayments = ISN_SKPaymentQueue.CanMakePayments;

 To Initializes the Store Kit with the set of previously defined products inside IOS Native Setting Window us the Init method. In case you want to define product via code, use the RegisterProduct method. You need to do this prior calling the Init method.

Example how to define products via code:

using SA.IOSNative.StoreKit;
...
string SMALL_PACK = "your.product.id1.here";
string NC_PACK = "your.product.id2.here";
ISN_SKPaymentQueue.RegisterProductId(SMALL_PACK);
ISN_SKPaymentQueue.RegisterProductId(NC_PACK);

 StoreKit initialization example:

using SA.IOSNative.StoreKit;
...
ISN_SKPaymentQueue.Init((ISN_SKInitResult result) => {
	Debug.Log("result.Products.Count " + result.Products.Count);
	Debug.Log("result.InvalidProductIdentifiers.Count " + result.InvalidProductIdentifiers.Count);
});

 The initialization result is represented as the ISN_SKInitResult object instance. You can only interact with products that were a part of  ISN_SKInitResult object Products array. Products that weren't recognized by Apple will be listed inside InvalidProductIdentifiers array.