1

How can I use SwiftyStoreKit to check if a user purchased a product with product ID com.X.X? I want to use the SwiftyStoreKit code to check if a user already purchased a product using inapp purchase system? I want to do that to determine whether I should show them a feature. How can I use Apple's inapp purchase system to check if a user already purchased a product? using swift

4

1 回答 1

1
func checkIfPurchaed () {
    let appleValidator = AppleReceiptValidator(service: .production, sharedSecret: "your-shared-secret")
    SwiftyStoreKit.verifyReceipt(using: appleValidator) { result in
        switch result {
        case .success(let receipt):
            let productId = "com.app.name.productID"
            // Verify the purchase of a Subscription
            let purchaseResult = SwiftyStoreKit.verifySubscription(
                ofType: .renewing //or .nonRenewing
                productId: productId,
                inReceipt: receipt)

            switch purchaseResult {
            case .purchased(let expiryDate, let items):
                print("\(productId) is valid until \(expiryDate)\n\(items)\n")
            case .expired(let expiryDate, let items):
                print("\(productId) is expired since \(expiryDate)\n\(items)\n")
            case .notPurchased:
                print("The user has never purchased \(productId)")
            }

        case .error(let error):
            print("Receipt verification failed: \(error)")
        }
    }

}
于 2019-03-16T14:36:13.673 回答