SwiftyStoreKit
SwiftyStoreKit copied to clipboard
Questions about the return value and processing order of the VerifyPurchase function
I tried a function like this:
func verifyPurchase(productId:String,sharedSecret:String) ->String {
var returnValue = "none"
let appleValidator = AppleReceiptValidator(service: .production, sharedSecret: sharedSecret)
SwiftyStoreKit.verifyReceipt(using: appleValidator) { result in
switch result {
case .success(let receipt):
let purchaseResult = SwiftyStoreKit.verifyPurchase(productId: productId, inReceipt: receipt)
switch purchaseResult {
case .purchased:
print(productId+"_purchased")
returnValue = "purchased"
case .notPurchased:
print(productId+"_notPurchased")
returnValue = "notPurchased"
}
case .error:
print(productId+"_error")
returnValue = "error"
}
}
return returnValue
}
print(verifyPurchase(productId:xxxxx,sharedSecret:xxxxx) )
However, the function always returns "none" even if the purchase is successful. What is the order in which the VerifyPurchase function is processed? How can this function return the correct value?