gpt4 book ai didi

swift - 类型 GameScene 不符合协议(protocol) "SKPaymentTransactionObserver"

转载 作者:搜寻专家 更新时间:2023-11-01 07:27:23 24 4
gpt4 key购买 nike

我有一个应用程序内购买来删除广告,但我只有一个错误阻止我编译我的代码。我确定我有必要的代码,但我认为缺少某些东西。谁能帮忙?

这是我的代码:

    import SpriteKit

import iAd

import StoreKit
var list = [SKProduct]()
var p = SKProduct()
class GameScene: SKScene, ADInterstitialAdDelegate, SKProductsRequestDelegate, SKPaymentTransactionObserver {
getProductInfo()


}

func getProductInfo() {
if(SKPaymentQueue.canMakePayments()) {
print("IAP is enabled, loading")
var productID:NSSet = NSSet(objects: "remove_ads")
let request: SKProductsRequest = SKProductsRequest(productIdentifiers: productID as! Set<String>)
request.delegate = self
request.start()
} else {
print("please enable IAPS")
}



}

func buyProduct() {
print("buy " + p.productIdentifier)
var pay = SKPayment(product: p)
SKPaymentQueue.defaultQueue().addTransactionObserver(self)
SKPaymentQueue.defaultQueue().addPayment(pay as SKPayment)
}
func paymentQueue(queue: SKPaymentQueue, updatedDownloads downloads: [SKDownload]) {

}
func paymentQueue(queue: SKPaymentQueue, removedTransactions transactions: [SKPaymentTransaction]) {

}
func paymentQueue(queue: SKPaymentQueue, res toreCompletedTransactionsFailedWithError error: NSError) {

}
func paymentQueue(queue: SKPaymentQueue, updatedTransactions transactions: [SKPaymentTransaction]) {

}
func productsRequest (request: SKProductsRequest, didReceiveResponse response: SKProductsResponse) {
print("product request")
var myProduct = response.products

for product in myProduct {
print("product added")
print(product.productIdentifier)
print(product.localizedTitle)
print(product.localizedDescription)
print(product.price)

list.append(product as! SKProduct )
}
}

func paymentQueueRestoreCompletedTransactionsFinished(queue: SKPaymentQueue!) {
print("transactions restored")

var purchasedItemIDS = []
for transaction in queue.transactions {
var t: SKPaymentTransaction = transaction as! SKPaymentTransaction

let prodID = t.payment.productIdentifier as String

switch prodID {
case "IAP id here": break


default:
print("IAP not setup")
}

}

var alert = UIAlertView(title: "Thank You", message: "Your purchase(s) were restored. You may have to restart the app before banner ads are removed.", delegate: nil, cancelButtonTitle: "OK")
alert.show()
}


func paymentQueue(queue: SKPaymentQueue!, updatedTransactions transactions: [AnyObject]!) {
print("add paymnet")

for transaction:AnyObject in transactions {
var trans = transaction as! SKPaymentTransaction
print(trans.error)

switch trans.transactionState {

case .Purchased, .Restored:
print("buy, ok unlock iap here")
//(prprint.productIdentifier)

let prodID = p.productIdentifier as String
switch prodID {
case "IAP id here":


var alert = UIAlertView(title: "Thank You", message: "You may have to restart the app before the banner ads are removed.", delegate: nil, cancelButtonTitle: "OK")
alert.show()
default:
print("IAP not setup")
}

queue.finishTransaction(trans)
break;
case .Failed:
print("buy error")
queue.finishTransaction(trans)
break;
default:
print("default")
break;

}
}
}

func finishTransaction(trans:SKPaymentTransaction)
{
print("finish trans")
}

最佳答案

SKPaymentTransactionObserver 唯一需要的函数是

paymentQueue(queue: SKPaymentQueue, updatedTransactions transactions: [SKPaymentTransaction])

你已经注释掉了。只需删除这些评论即可!

编辑:啊,问题是您在关闭类(class)时没有包含其余功能!

你可以在这里看到:

class GameScene: SKScene, ADInterstitialAdDelegate, SKProductsRequestDelegate, SKPaymentTransactionObserver {
getProductInfo()


}

最后一个大括号需要剪切并粘贴到文件的最后。

关于swift - 类型 GameScene 不符合协议(protocol) "SKPaymentTransactionObserver",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35097039/

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