我的 iap 问题从用户没有付款方式开始。iaps 在沙盒(也被中断的模拟)和现实世界中工作。但是在真正的应用程序中(从 appstore 下载 - 我在 ios 12 - iphone 6 中测试过),如果我没有支付方式应用程序警告我添加一个。然后 appstore 应用程序打开(我的应用程序进入后台),我输入所有要购买的信用卡功能。一切顺利,appstore 提示我您购买了产品。但是在返回我的应用程序(将其置于前台)之后,什么也没有发生。我无法获得有关交易的任何信息。即使我添加了 appdidbecomeactive 观察者来再次捕获未完成的交易。再次没有...然后我在应用程序启动中添加了 unfinishedTransaction 函数。如果我终止应用程序并重新开始。它捕获未完成的交易并执行我的代码。但是没有付款方式的用户认为该应用程序不起作用,他们要求退款。所以他们是对的,我正在偿还或更改他们的数据库。我该如何处理这个问题?我什至无法在沙盒中测试它。每次我给苹果定价测试。请帮我。
问问题
117 次
1 回答
0
otherViewcontroller
@objc func saveBtnTUI() {
mainVC.messageSN(subject: subjectTF.text!, explain: explainTV.text!)
}
在调用支付功能之后,我正在处理我的数据库连接以在 mainviewcontroller 中打开新草稿......
import StoreKit
MainViewcontroller, SKPaymentTransactionObserver
func pay() {
SKPaymentQueue.default().add(SKPayment(product: product)) SKPaymentQueue.default().add(self)
}
func paymentQueue(_ queue: SKPaymentQueue, updatedTransactions transactions: [SKPaymentTransaction]) {
for transaction in transactions {
...
case .purchased: complete(transaction: transaction); break
case .failed: fail(transaction: transaction); break
...
}
}
func complete(transaction: SKPaymentTransaction) {
print("complete...")
DispatchQueue.main.async { self.paymentID = transaction.transactionIdentifier!; self.paySN()}
SKPaymentQueue.default().finishTransaction(transaction); SKPaymentQueue.default().remove(self)
}
func fail(transaction: SKPaymentTransaction) {
DispatchQueue.main.async {self.view.viewWithTag(999)?.removeFromSuperview()}
if let err = transaction.error as? SKError {
if err.code != .paymentCancelled {
var mStr:String = "", statusStr:String = ""; print("fail", err.localizedDescription, err.code.self)
if err.code == .clientInvalid {mStr = "..."; statusStr = mStr}
else if err.code == .cloudServiceNetworkConnectionFailed {mStr = "..."; statusStr = mStr}
else if err.code == .cloudServicePermissionDenied {mStr = "..."; statusStr = mStr}
else if err.code == .cloudServiceRevoked {mStr = "..."; statusStr = mStr}
else if err.code == .paymentInvalid {mStr = "..."; statusStr = mStr}
else if err.code == .paymentNotAllowed {mStr = "..."; statusStr = mStr}
else if err.code == .storeProductNotAvailable {mStr = "..."; statusStr = mStr}
else {mStr = "..."; statusStr = "..."}
if #available(iOS 12.2, *) {
if err.code == .invalidOfferIdentifier {mStr = "..."; statusStr = mStr}
else if err.code == .invalidOfferPrice {mStr = "..."; statusStr = mStr}
else if err.code == .invalidSignature {mStr = "..."; statusStr = mStr}
else if err.code == .missingOfferParams {mStr = "..."; statusStr = mStr}
} else {
mStr = "..."; statusStr = "..."
}
let alert = UIAlertController(title: NSLocalizedString("ERROR", comment: ""), message: mStr, preferredStyle: .alert)
let cancelA = UIAlertAction(title: NSLocalizedString("OK", comment: ""), style: .cancel, handler: nil); alert.addAction(cancelA)
self.present(alert, animated: true, completion: nil)
self.paymentStatusSN(status: "fail", message: statusStr)
}
else {print("..."); self.paymentStatusSN(status: "cancel", message: "...")}
}
else {
let alert = UIAlertController(title: NSLocalizedString("ERROR", comment: ""), message: "...", preferredStyle: .alert)
let cancelA = UIAlertAction(title: NSLocalizedString("OK", comment: ""), style: .cancel, handler: nil); alert.addAction(cancelA)
self.present(alert, animated: true, completion: nil)
self.paymentStatusSN(status: "fail", message: "...")
}
SKPaymentQueue.default().finishTransaction(transaction); SKPaymentQueue.default().remove(self)
}
于 2020-12-10T18:37:09.937 回答