0

Instruction how to create a StoreKit configuration file:

https://developer.apple.com/documentation/xcode/setting-up-storekit-testing-in-xcode/#

I use SwiftyStoreKit but the pure StoreKit behaviour should be the same.

I can get subscription info and purchase subscription so it seems I set up my app correctly but how to check if user is already subscribed now?

From SwiftyStoreKit readme:

let appleValidator = AppleReceiptValidator(service: .production, sharedSecret: "your-shared-secret")
SwiftyStoreKit.verifyReceipt(using: appleValidator) { result in
    switch result {
    case .success(let receipt):
        let productId = "com.musevisions.SwiftyStoreKit.Purchase1"
        // Verify the purchase of Consumable or NonConsumable
        let purchaseResult = SwiftyStoreKit.verifyPurchase(
            productId: productId,
            inReceipt: receipt)
            
        switch purchaseResult {
        case .purchased(let receiptItem):
            print("\(productId) is purchased: \(receiptItem)")
        case .notPurchased:
            print("The user has never purchased \(productId)")
        }
    case .error(let error):
        print("Receipt verification failed: \(error)")
    }
}

I tried both sandbox and production params. sharedSecret doesn't exist in my case but it is optional in AppleReceiptValidator so I don't use it.

I even tried to purchase a subscription, fetch a receipt and call verifyReceipt. Fetching receipt works but verifying receipt constantly returns 21002 error code ("malformedOrMissingData").

Gargo
  • 1,135
  • 1
  • 10
  • 21

0 Answers0