gpt4 book ai didi

ios - SwiftyStoreKit 如何检查用户是否购买了产品?

转载 作者:行者123 更新时间:2023-11-28 06:06:37 28 4
gpt4 key购买 nike

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

最佳答案

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)")
}
}

}

关于ios - SwiftyStoreKit 如何检查用户是否购买了产品?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48024076/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com