在我的应用程序中,我有一个函数可以创建 NSRURLSession 并使用以下命令发送 NSURLRequest
sesh.dataTaskWithRequest(req, completionHandler: {(data, response, error)
在此任务的完成块中,我需要进行一些计算,将 UIImage 添加到调用视图控制器。我有一个名为
func displayQRCode(receiveAddr, withAmountInBTC:amountBTC)
它执行 UIImage 添加计算。如果我尝试在完成块内运行视图添加代码,Xcode 会抛出一个错误,指出我无法在后台进程中使用布局引擎。所以我在 SO 上找到了一些代码,尝试在主线程上对方法进行排队:
let time = dispatch_time(DISPATCH_TIME_NOW, Int64(0.0 * Double(NSEC_PER_MSEC)))
dispatch_after(time, dispatch_get_main_queue(), {
let returned = UIApplication.sharedApplication().sendAction("displayQRCode:", to: self.delegate, from: self, forEvent: nil)
})
但是,我不知道如何将参数“receiveAddr”和“amountBTC”添加到此函数调用中。我将如何做到这一点,或者有人可以建议一种将方法调用添加到应用程序主队列的最佳方法?