gpt4 book ai didi

ios - 应用内购买不起作用

转载 作者:行者123 更新时间:2023-11-30 14:15:57 25 4
gpt4 key购买 nike

我正在制作游戏,但遇到了问题:每次我在其中进行购买时,它都会返回失败的交易。我调用这个函数来开始交易:

func buyProduct() {
let payment:SKPayment = SKPayment(product: product)
SKPaymentQueue.defaultQueue().addPayment(payment)
}

我在 SandBox 测试器中获得了几个用户,并免费设置了应用内购买的价格。有什么问题吗?

var product: SKProduct!
//used in viewDidLoad

SKPaymentQueue.defaultQueue().addTransactionObserver(self)
self.getProductInfo()

func productsRequest(request: SKProductsRequest!, didReceiveResponse response: SKProductsResponse!) {
let products = response.products
if (products.count != 0){
product = products[0] as! SKProduct
}
}

func getProductInfo() {
if (SKPaymentQueue.canMakePayments()){
let productID:NSSet = NSSet(object: "id.unique")
let request:SKProductsRequest = SKProductsRequest(productIdentifiers: productID as Set<NSObject>)
request.delegate = self
request.start()
}

}

func paymentQueue(queue: SKPaymentQueue!, updatedTransactions transactions: [AnyObject]!) {
for transaction:AnyObject in transactions {
if let trans:SKPaymentTransaction = transaction as? SKPaymentTransaction{
switch trans.transactionState{
case .Purchased:
self.removeAds()
println("success")
SKPaymentQueue.defaultQueue().finishTransaction(transaction as! SKPaymentTransaction)
break
case .Failed:
println("failed")
showAlert("Error", message: "Ooops, there is transaction problem")
SKPaymentQueue.defaultQueue().finishTransaction(transaction as! SKPaymentTransaction)
break
case .Restored:
println("restored")
SKPaymentQueue.defaultQueue().restoreCompletedTransactions()
break
default:
break
}
}
}
}

最佳答案

你在真实设备上测试过吗?

在应用程序中购买不适用于模拟器,它将失败并出现这样的错误。

Error Domain=SKErrorDomain Code=0 "Cannot connect to iTunes Store" UserInfo=0x7f98b8fda180 {NSLocalizedDescription=Cannot connect to iTunes Store}

关于ios - 应用内购买不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31172982/

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