I'm trying to create in app purchases on an SKScene
in my game. The scene is called coinShop. Basically, an IAP that gives the user 300 coins. When I tried copying code, it said SKScene can not conform to the delegates I tried adding. If anybody knows how do in app purchases with a scene instead of a viewcontroller, I would love to know. Here is all the code relating to in app purchases
in the didMoveToView(), i have
SKPaymentQueue.defaultQueue().addTransactionObserver(self)
requestProductInfo()
productIDs.append("com.ClearRockTechnologies.alien-anarchy.300Coins")
and then i have the following functions
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)
}
}
}
and here are my two errors,
Type 'coinShop' does not conform to protocol 'SKPaymentTransactionObserver'
'NSSet' is not implicitly convertible to 'Set'; did you mean to use 'as' to explicitly convert?
Error 1 has no suggestion, and error 2 tells me to add as "Set< NSObject >" to this line
let productRequest = SKProductsRequest(productIdentifiers: productIdentifiers as Set<NSObject> )
but I clearly already have that. Any help would be appreciated.