2

Xcode 12 introduced StoreKit Configuration files which are great for testing basic StoreKit functionality before delving into App Store Connect, Sandbox and all that.

Is there a way to determine at run-time (or even at compile-time) whether the scheme's StoreKit Configuration value is set to 'none' or some file?

Jaysen Marais
  • 3,956
  • 28
  • 44

1 Answers1

2

I was just wondering the same, because since I perform local receipt validation, I had to use the right certificate: StoreKit or Apple's root.

The solution is pretty simple: add a new product inside your .storekit file to check if you are using the local config or the sandbox/App Store one.

Add a new product ID called using_store_kit_conf then pass the array of IDs to SKProductsRequest containing also this one. When you get the list of products in the delegate, check if the using_store_kit_conf product is present to determine if you're using the StoreKit Configuration file.

If you list all your products to the user, remember to filter out the using_store_kit_conf product.

storekit file

Sample:

static let premiumOneTime = "premium_one_time"
static let usingStoreKitConfiguration = "using_store_kit_conf"
static let productIds: Set<String> = [InAppPurchase.premiumOneTime, InAppPurchase.usingStoreKitConfiguration]
private var products: [SKProduct] = []

Pass all the IDs:

productsRequest = SKProductsRequest(productIdentifiers: InAppPurchase.productIds)

Delegate:

func productsRequest(_ request: SKProductsRequest, didReceive response: SKProductsResponse) {
    self.products = response.products
    print("InAppPurchase products: ", response.products)
}

Check if using StoreKit Configuration:

var isUsingStoreKitConfiguration: Bool {
    products.contains(where: { product in product.productIdentifier == InAppPurchase.usingStoreKitConfiguration })
}

NOTE: This only works after you have loaded the products list, otherwise isUsingStoreKitConfiguration will always return false.

Kazikal
  • 156
  • 7