I might be doing something wrong, but I can't seem to make my function wait for the data to load before it continues with the next sections. In this case, I need requestProductInfo() to supply the data before the alert in the next step to show. From what I have read, dispatch_async would be the correct way to do it, but it does not seem to be working. Am I doing something wrong?
func purchaseRequest() {
requestProductInfo()
//NEED TO HOLD UNTIL PRODUCTS REQUEST IS COMPLETED
dispatch_async(dispatch_get_main_queue()) {
print("Product1: \(self.productsArray)")
let aSC = UIAlertController(title: "Premium App Required", message: "Premium App is Required for this feature. Would you like to purchase it for $0.99?", preferredStyle: UIAlertControllerStyle.ActionSheet)
let buyAction = UIAlertAction(title: "Purchase", style: UIAlertActionStyle.Default) { (action) -> Void in
let payment = SKPayment(product: self.productsArray)
SKPaymentQueue.defaultQueue().addPayment(payment)
}
let cancelAction = UIAlertAction(title: "Cancel", style: UIAlertActionStyle.Cancel) { (action) -> Void in
}
aSC.addAction(buyAction)
aSC.addAction(cancelAction)
self.presentViewController(aSC, animated: true, completion: nil)
}
}
Thanks!