I am implementing no ads in app purchase to my sprite kit game and so far I have the following :
func requestProductData()
{
if SKPaymentQueue.canMakePayments() {
let request = SKProductsRequest(productIdentifiers:
self.productIdentifiers as Set<NSObject>)
request.delegate = self
request.start()
} else {
var alert = UIAlertController(title: "In-App Purchases Not Enabled", message: "Please enable In App Purchase in Settings", preferredStyle: UIAlertControllerStyle.Alert)
alert.addAction(UIAlertAction(title: "Settings", style: UIAlertActionStyle.Default, handler: { alertAction in
alert.dismissViewControllerAnimated(true, completion: nil)
let url: NSURL? = NSURL(string: UIApplicationOpenSettingsURLString)
if url != nil
{
UIApplication.sharedApplication().openURL(url!)
}
}))
alert.addAction(UIAlertAction(title: "Ok", style: UIAlertActionStyle.Default, handler: { alertAction in
alert.dismissViewControllerAnimated(true, completion: nil)
}))
}
}
func productsRequest(request: SKProductsRequest!, didReceiveResponse response: SKProductsResponse!) {
var products = response.products
if (products.count != 0) {
for var i = 0; i < products.count; i++
{
self.product = products[i] as? SKProduct
self.productsArray.append(product!)
}
} else {
println("No products found")
}
products = response.invalidProductIdentifiers
for product in products
{
println("Product not found: \(product)")
}
}
func buyProduct() {
let payment = SKPayment(product: productsArray[0])
SKPaymentQueue.defaultQueue().addPayment(payment)
}
func paymentQueue(queue: SKPaymentQueue!, updatedTransactions transactions: [AnyObject]!) {
for transaction in transactions as! [SKPaymentTransaction] {
switch transaction.transactionState {
case SKPaymentTransactionState.Purchased:
println("Transaction Approved")
println("Product Identifier: \(transaction.payment.productIdentifier)")
self.deliverProduct(transaction)
SKPaymentQueue.defaultQueue().finishTransaction(transaction)
case SKPaymentTransactionState.Failed:
println("Transaction Failed")
SKPaymentQueue.defaultQueue().finishTransaction(transaction)
default:
break
}
}
}
func deliverProduct(transaction:SKPaymentTransaction) {
if transaction.payment.productIdentifier == "productId"
{
println("unlocking")
}
}
func restorePurchases() {
SKPaymentQueue.defaultQueue().addTransactionObserver(self)
SKPaymentQueue.defaultQueue().restoreCompletedTransactions()
}
func paymentQueueRestoreCompletedTransactionsFinished(queue: SKPaymentQueue!) {
println("Transactions Restored")
var purchasedItemIDS = []
for transaction:SKPaymentTransaction in queue.transactions as! [SKPaymentTransaction] {
if transaction.payment.productIdentifier == "productId"
{
println("unlocking")
// Unlock Feature
}
}
The game has a very minimalist UI: it has a pause button, which if pressed pauses everything but my background animations, adds opacity mask to some nodes and darkens the screen in general. It also prompts no ads button and level changer interface.
Ok so the problems I have are: 1) if I press no ads button, the alert view shows up and pauses everything and when dismissed, starts everything again. Is there a way to call this alert view so it does not interact with my UI?
2) It also asks me to login when the game is loaded. How do I stop this?