本文介绍了GTLServiceYouTube未调用executeQuery回调的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

GTLServiceYouTube executeQuery 当我在后台线程中执行它时未调用回调。视频不会上传。当我在主线程中执行它时它工作正常。我得到回调和视频也上传。我可以通过强制 executeQuery 在主线程中运行来解决这个问题,但这会影响UI性能。我该如何解决这个问题?

GTLServiceYouTube executeQuery callback not called when I execute it in background thread.Video wont get uploaded. It works fine when I execute it in main thread.I get callbacks and video is also uploaded. I can solve this by forcing executeQuery to run in main thread but that affects the UI performance. How can I solve this issue?

我的代码是这样的,

self.uploadFileTicket = [service executeQuery:query
                                completionHandler:^(GTLServiceTicket *ticket,
                                                    GTLYouTubeVideo *uploadedVideo,
                                                    NSError *error) {
// code to handle
}


推荐答案

我找到了解决方案!这里发生的事情是,当我在后台线程中运行代码时,在回调到来之前线程被分离。因此我们没有得到回调。当我在主线程中运行它时,主线程始终保持活动状态。因此我们得到了回调。因此,可以通过使用以下代码使当前线程等待来解决此问题。

I found a solution! Here whats happening is, when I run the code in background thread, before the callback comes the thread is detached. Hence we don't get the callback. When I run it in main thread, main Thread remains alive throughout. Hence we do get callback. Hence this problem can be solved by making current thread to wait using following code.

[[NSRunLoop currentRunLoop] runUntilDate:stopDate];

这篇关于GTLServiceYouTube未调用executeQuery回调的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 13:19