我可能做错了什么,但我似乎无法让我的函数在继续下一部分之前等待数据加载。在这种情况下,我需要 requestProductInfo()在下一步显示警报之前提供数据。从我所读到的,dispatch_async将是正确的方法,但它似乎没有工作。我做错了吗?
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)
}
}
谢谢!