在 dispatch_async 中上传 UIImage

Upload UIImage in dispatch_async

我有问题。我在 dispatch_async 中调用了一些方法。但是在 callMethod2 的不同对象中,我正在使用 [NSURLConnection sendAsynchronousRequest 上传图像。但是上传后,它没有显示我的回应。 (但是,当我在没有 dispatch_async 的情况下调用 callMethod2 时,效果很好)。请问哪里有问题?

dispatch_async(dispatch_get_global_queue( DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^(void){
    [offline callMethod1];
    [offline callMethod2];
});

上传图片

[NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue currentQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {

    NSLog("Never show me me this log");

}];

您在非主线程的线程上调用 NSLog(也称为异步调用),因此您不会看到 NSLog,因为它必须 运行 在主线程上。

您可以让完成块在完成时以其他方式通知您。我发现的最好方法是使用 https://github.com/kseebaldt/deferred,它允许您发送一个承诺(我保证我会做这件事并在完成时通知您)。