gpt4 book ai didi

ios - Swift 应用内购买 : Constant prompt to sign in; incorrectly handling . finishTransaction?

转载 作者:行者123 更新时间:2023-11-28 08:43:22 26 4
gpt4 key购买 nike

我包含了一些非消耗性 IAP,但我在加载我的应用程序时遇到了问题,因为它似乎不断提示我登录到我设置的测试帐户用户。

我看了类似的问题后,我相信这是因为我最初没有在每个 .case 中添加以下行:

 SKPaymentQueue.defaultQueue().finishTransaction(transaction as! SKPaymentTransaction) 

正如您从我下面的代码中看到的那样,它已添加到每个 .case 中。为了重新测试,我创建了一个额外的测试帐户,但我现在得到了完全相同的结果(在每个 viewDidLoad 上我都被提示登录 2 个测试帐户...)。

这让我觉得 SKPaymentQueue.defaultQueue().finishTransaction(transaction as!SKPaymentTransaction) 没有按预期工作?

如有任何帮助,我们将不胜感激。

override func viewDidLoad() {
SKPaymentQueue.defaultQueue().addTransactionObserver(self)
}

紧随其后

func paymentQueue(queue: SKPaymentQueue, updatedTransactions transactions: [SKPaymentTransaction])    {
print("received response ok");
if product_id == "xxxxxxxxx" {
for transaction:AnyObject in transactions {
if let trans:SKPaymentTransaction = transaction as? SKPaymentTransaction{
switch trans.transactionState {
case .Purchased:
print("Product Purchased");
SKPaymentQueue.defaultQueue().finishTransaction(transaction as! SKPaymentTransaction)
defaults.setBool(true , forKey: "Purchased")
print("Set key ok")
break;
case .Failed:
print("Purchased Failed");
SKPaymentQueue.defaultQueue().finishTransaction(transaction as! SKPaymentTransaction)
break;
case .Restored:
print("Already Purchased");
SKPaymentQueue.defaultQueue().restoreCompletedTransactions()
SKPaymentQueue.defaultQueue().finishTransaction(transaction as! SKPaymentTransaction)
default:
break;
}
}
}
}
else {
//blah blah
}

}

我遇到这个问题是因为 finishTransaction 没有按预期工作,还是原始事务“卡住了”?

编辑:这是我调用 SKPaymentQueue.defaultQueue().addPayment(payment);

func buyProduct(product: SKProduct){
print("Sending the Payment Request to Apple");
let payment = SKPayment(product: product)
SKPaymentQueue.defaultQueue().addPayment(payment);

}


func productsRequest (request: SKProductsRequest, didReceiveResponse response: SKProductsResponse) {

let count : Int = response.products.count
if (count>0) {
var validProducts = response.products
let validProduct: SKProduct = response.products[0] as SKProduct
if (validProduct.productIdentifier == self.product_id) {
print(validProduct.localizedTitle)
print(validProduct.localizedDescription)
print(validProduct.price)
buyProduct(validProduct);
} else {
print(validProduct.productIdentifier)
}
} else {
print("nothing")
}
}

最佳答案

这已“自行修复”。我想现在我已经添加了:

SKPaymentQueue.defaultQueue().finishTransaction(transaction as! SKPaymentTransaction) 

每次我重新登录时,它都在完成之前“卡住”的交易,并将它们从积压中移除?

无论哪种方式;现在已经解决了。

关于ios - Swift 应用内购买 : Constant prompt to sign in; incorrectly handling . finishTransaction?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35918106/

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