I have a simple app, with one non-consumable in-app purchase option.
From my initial view controller I have a single 'enter' button.
This button will send a 'free' user (has not made non-consumable purchase) to one TabBarController "A" and series of views and a 'paid' user to the other TabBarController "B" a different set of views. These views will never intersect.
I would like to check wether my code is able to distinguish effectively as to whether a user has made the in-app purchase or otherwise.
Here is my code:
import UIKit
import StoreKit
class MainMainViewController: UIViewController, UIScrollViewDelegate, SKProductsRequestDelegate, SKPaymentTransactionObserver {
let defaults = NSUserDefaults.standardUserDefaults()
var product_id: NSString?;
...
override func viewDidLoad() {
product_id = "some.iap.id";
SKPaymentQueue.defaultQueue().addTransactionObserver(self)
super.viewDidLoad()
}
@IBAction func Enter(sender: AnyObject) {
//Check if product is purchased
if (defaults.boolForKey("purchased")){
print("User has purchased da goods!")
// Grant or otherwise full access based on whether user has purchased/not purchased.
// Goto TabBarController A - FULL Access:
let vc = self.storyboard!.instantiateViewControllerWithIdentifier("TabBarControllerPaid") as! TabBarControllerPaid
self.presentViewController(vc, animated: true, completion: nil)
}
else if (!defaults.boolForKey("purchased")){
print("user has NOT purchased yet")
// Goto TabBarController B - PARTIAL Access:
let vc = self.storyboard!.instantiateViewControllerWithIdentifier("TabBarControllerFree") as! TabBarControllerFree
self.presentViewController(vc, animated: true, completion: nil)
}
}
}
Many thanks in advance for any answers, comments or thoughts :-)