简体   繁体   English

没有使用后台线程调用连接委托方法,为什么? (iPhone SDK)

[英]Connection delegate methods not called with background thread, Why ? (iPhone SDK)

Connection delegate methods not called with background thread, Why ? 没有使用后台线程调用连接委托方法,为什么?

In program i have created background thread and that thread set connection delegates, by setting ObjNSURLConnection.delegate = AnotherClass, and that AnotherClass contains NSURLConnection delegate methods. 在程序中,我通过设置ObjNSURLConnection.delegate = AnotherClass创建了后台线程并设置了该线程的连接委托,并且AnotherClass包含NSURLConnection委托方法。

But when i debug a code i have found that NSURLConnection delegate method doesn't called. 但是,当我调试代码时,我发现未调用NSURLConnection委托方法。 Any reason , Why they are not called ? 有什么理由,为什么不叫他们? How to solve this issue? 如何解决这个问题?

NSURLConnection schedules notifications for events on the runloop on which it was called. NSURLConnection计划在调用它的runloop上的事件的通知。 You are likely neglecting to run the runloop for your background thread. 您可能会忽略为后台线程运行runloop。

You need to explicitly run the runloop after starting the connection. 开始连接后,您需要显式运行runloop。 Try adding this line of code 尝试添加此行代码

[[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]]; [[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM