使用Swift通过应用内购买获得捐赠
我计划实施应用内购买,作为应用开发的支持。我在AppStore connect中制作了一个可消费的IAP,我使用了以下代码使用Swift通过应用内购买获得捐赠,swift,xcode,in-app-purchase,storekit,Swift,Xcode,In App Purchase,Storekit,我计划实施应用内购买,作为应用开发的支持。我在AppStore connect中制作了一个可消费的IAP,我使用了以下代码 @IBAction func supportDevelopmentButtonHasBeenTapped(_ sender: Any) { if SKPaymentQueue.canMakePayments() { let paymentReq = SKMutablePayment() paymentReq.productId
@IBAction func supportDevelopmentButtonHasBeenTapped(_ sender: Any) {
if SKPaymentQueue.canMakePayments() {
let paymentReq = SKMutablePayment()
paymentReq.productIdentifier = productID
SKPaymentQueue.default().add(paymentReq)
} else {
print("user cannot make payment")
}
}
这个功能是:
func paymentQueue(_ queue: SKPaymentQueue, updatedTransactions transactions: [SKPaymentTransaction]) {
for transaction in transactions {
if transaction.transactionState == .purchased {
let thanksAlert = UIAlertController(title: "Thanks!", message: "Thanks For Your Support", preferredStyle: UIAlertController.Style.alert)
thanksAlert(UIAlertAction(title: "Back", style: UIAlertAction.Style.default, handler: nil))
self.present(thanksAlert, animated: true, completion: nil)
return
} else if transaction.transactionState == .failed {
print("")
}
}
}
我的问题是用户不能多次购买,我如何才能让用户支持他想要的内容?我认为您需要调用“transaction.transactionState==.purchased”
SKPaymentQueue.default().finishTransaction(transaction)