我试图在我的游戏中SKScene
创建应用内购买。这个场景叫做coinShop。基本上,IAP为用户提供300个硬币。当我尝试复制代码时,它说SKScene不能符合我尝试添加的代表。如果有人知道应用程序如何购买场景而不是视图控制器,我很想知道。以下是与应用内购买相关的所有代码
SKPaymentQueue.defaultQueue().addTransactionObserver(self)
requestProductInfo()
productIDs.append("com.ClearRockTechnologies.alien-anarchy.300Coins")
然后我有以下功能
func requestProductInfo() {
if SKPaymentQueue.canMakePayments() {
let productIdentifiers = NSSet(array: productIDs)
let productRequest = SKProductsRequest(productIdentifiers: productIdentifiers as Set<NSObject> )
productRequest.delegate = self
productRequest.start()
}
else {
print("Cannot perform In App Purchases.")
}
}
func productsRequest(request: SKProductsRequest, didReceiveResponse response: SKProductsResponse) {
if response.products.count != 0 {
for product in response.products {
productsArray.append(product)
}
}
else {
print("There are no products.")
}
if response.invalidProductIdentifiers.count != 0 {
print(response.invalidProductIdentifiers.description)
}
}
func showActions() {
let payment = SKPayment(product: self.productsArray[0] as SKProduct)
SKPaymentQueue.defaultQueue().addPayment(payment)
//self.transactionInProgress = true
}
func paymentQueue(queue: SKPaymentQueue!, updatedTransactions transactions: [AnyObject]!) {
for transaction in transactions as! [SKPaymentTransaction] {
switch transaction.transactionState {
case SKPaymentTransactionState.Purchased:
print("Transaction completed successfully.")
SKPaymentQueue.defaultQueue().finishTransaction(transaction)
coins+=300
NSUserDefaults.standardUserDefaults().setInteger(coins, forKey: "coins")
case SKPaymentTransactionState.Failed:
print("Transaction Failed");
SKPaymentQueue.defaultQueue().finishTransaction(transaction)
default:
print(transaction.transactionState.rawValue)
}
}
}
这是我的两个错误,
键入&#39; coinShop&#39;不符合协议&#39; SKPaymentTransactionObserver&#39;
&#39;的NSSet&#39;不能隐含地转换为&#39; Set&#39 ;;你的意思是使用&#39;作为&#39;明确转换?
错误1没有任何建议,错误2告诉我添加为&#34; Set&lt; NSObject&gt;&#34;到这条线
let productRequest = SKProductsRequest(productIdentifiers: productIdentifiers as Set<NSObject> )
但我显然已经有了。任何帮助,将不胜感激。