You can set-up In-App-Purchases inside of an SKScene, You may need to tweak some code but it will work. Here's an example
import Spritekit
import Storekit
class Store:SKScene, SKProductsRequestDelegate, SKPaymentTransactionObserver {
override func didMoveToView {
// Set IAPS
if(SKPaymentQueue.canMakePayments()) {
println("IAP is enabled, loading")
var productID:NSSet = NSSet(objects: "bundle id", "bundle id")
var request: SKProductsRequest = SKProductsRequest(productIdentifiers: productID)
request.delegate = self
request.start()
} else {
println("please enable IAPS")
}
}
// 2
func btnRemoveAds() {
for product in list {
var prodID = product.productIdentifier
if(prodID == "bundle id") {
p = product
buyProduct()
break;
}
}
}
// 3
func btnAddCoins() {
for product in list {
var prodID = product.productIdentifier
if(prodID == "bundle id") {
p = product
buyProduct()
break;
}
}
}
// 4
func removeAds() {
println("ads removed")
}
// 5
func addCoins() {
println("added 50 coins")
}
// 6
func RestorePurchases() {
SKPaymentQueue.defaultQueue().addTransactionObserver(self)
SKPaymentQueue.defaultQueue().restoreCompletedTransactions()
}
var list = [SKProduct]()
var p = SKProduct()
// 2
func buyProduct() {
println("buy " + p.productIdentifier)
var pay = SKPayment(product: p)
SKPaymentQueue.defaultQueue().addTransactionObserver(self)
SKPaymentQueue.defaultQueue().addPayment(pay as SKPayment)
}
//3
func productsRequest(request: SKProductsRequest!, didReceiveResponse response: SKProductsResponse!) {
println("product request")
var myProduct = response.products
for product in myProduct {
println("product added")
println(product.productIdentifier)
println(product.localizedTitle)
println(product.localizedDescription)
println(product.price)
list.append(product as SKProduct)
}
}
// 4
func paymentQueueRestoreCompletedTransactionsFinished(queue: SKPaymentQueue!) {
println("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 "bundle id":
println("remove ads")
removeAds()
case "bundleid":
println("add coins to account")
addCoins()
default:
println("IAP not setup")
}
}
}
// 5
func paymentQueue(queue: SKPaymentQueue!, updatedTransactions transactions: [AnyObject]!) {
println("add paymnet")
for transaction:AnyObject in transactions {
var trans = transaction as SKPaymentTransaction
println(trans.error)
switch trans.transactionState {
case .Purchased:
println("buy, ok unlock iap here")
println(p.productIdentifier)
let prodID = p.productIdentifier as String
switch prodID {
case "bundle id":
println("remove ads")
removeAds()
case "bundle id":
println("add coins to account")
addCoins()
default:
println("IAP not setup")
}
queue.finishTransaction(trans)
break;
case .Failed:
println("buy error")
queue.finishTransaction(trans)
break;
default:
println("default")
break;
}
}
}
// 6
func finishTransaction(trans:SKPaymentTransaction)
{
println("finish trans")
}
//7
func paymentQueue(queue: SKPaymentQueue!, removedTransactions transactions: [AnyObject]!)
{
println("remove trans");
}
You would call the removeAdsButton() or whatever when you want to make a purchase.