首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >SwiftyStoreKit如何查看用户是否购买了产品?

SwiftyStoreKit如何查看用户是否购买了产品?
EN

Stack Overflow用户
提问于 2017-12-29 22:26:20
回答 1查看 816关注 0票数 1

如何使用SwiftyStoreKit检查用户是否购买了产品ID为com.X.X的产品?我想使用SwiftyStoreKit代码来检查用户是否已经使用应用程序购买系统购买了产品?我想这样做是为了确定我是否应该向他们显示一个功能。我如何使用苹果的应用内购买系统来检查用户是否已经购买了产品?使用swift

EN

回答 1

Stack Overflow用户

发布于 2019-03-16 22:36:14

代码语言:javascript
复制
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)")
        }
    }

}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/48024076

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档