0
我有这样的代码,用于验证IAP收入和我试着基于什么状态此功能被返回来显示一个警告,但我不断收到此错误UIAlertView中的问题与session.dataTaskWithRequest
"This application is modifying the autolayout engine from a background thread, which can lead to engine corruption and weird crashes. This will cause an exception in a future release. ....... (then a whole list of numbers and stuff)"
这是代码我正在使用,(相当简化)。我猜测它与线程和异步的东西有关,我不太确定。我如何以正确的方式做到这一点?
func verifyPaymentReceipt(transaction: SKPaymentTransaction, completion : (status : Bool) ->()) {
.... //Verify Receipt code
let task = session.dataTaskWithRequest(storeRequest, completionHandler: { data, response, error in
if(error != nil){
//Handle Error
}
else{
completion(status: true)
}
}
这是怎么了调用该函数:
verifyPaymentReceipt(transaction, completion: { (status) ->() in
if status {
print("Success")
self.showMessage(true)
} else {
print("Fail")
self.showMessage(false)
}
})
而这正是演出消息功能
func showMessage(message: Bool) {
var alert = UIAlertView()
if message == true {
alert = UIAlertView(title: "Thank You", message: "Your purchase(s) are succeessful", delegate: nil, cancelButtonTitle: "Ok")
} else {
alert = UIAlertView(title: "Thank You", message: "Your purchase(s) restore failed, Please try again.", delegate: nil, cancelButtonTitle: "Ok")
}
alert.show()
}
是的我知道'UIAlertView'已被弃用。 (很难不知道什么时候这个黄色的感叹号不断提醒你),但无论如何感谢!哪里是添加它的理想场所?在'verifyPaymentReceipt()'函数调用之后,还是应该在'task'之后? –
这取决于哪个块在后台线程中运行。您可以通过添加一个断点并在您点击它时在左侧的调试导航列表中查看线程号来查找。 –
谢谢!我正在学习编程,这是我的第一个应用程序。像你这样的人给了我很多需要的指导,我真的很感激。谢谢!! –