English 中文(简体)
NSURLConnection in its own thread not work without spin loop
原标题:NSURLConnection in its own thread not working without spin loop

除非我有缝.,否则我会遇到一个没有上载的客观上载荷舱的问题(没有上报/成功代表,服务器没有接到任何要求)。 它完美地运作。

I m new to objective-C, The setup is as follows: Main app instantiates a C++ class (cppClass) that runs a static function (cppFuncA) in a separate pThread.

法定职能(PppFuncA)即为客观的C类/目标(上载Func)提供一些数据并上载。

CppClass {
    static void cppFuncA (...);
} 

cppFuncA(...) {
    UploadFunc* uploader = [[[UploadFunc alloc] retain] init];
    while (condition) {
        ...
        [uploader uploadData:(NSData*)data];
    }
    [uploader release]
}

Uploader.h

@interface UploadFunc : NSObject
{
    bool conditional;
}
- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error;
- (void)connectionDidFinishLoading:(NSURLConnection *)connection;
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response;
- (void) uploadData:(NSData*)data;
@end

Uploader.mm

@implementation UploadFeedback
- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
{
    conditional = false;
    [connection release];
    NSLog(@"Connection failed! Error - %@ %@",
          [error localizedDescription],
          [[error userInfo] objectForKey:NSURLErrorFailingURLStringErrorKey]);
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
    conditional = false;
    NSLog(@"Succeeded! Received %d bytes of data",0);
    [connection release];
}
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
    NSLog(@"Response=%@", response);
}

-(void) uploadData:(NSData*)data
{
    …
    NSMutableURLRequest *theRequest=[NSMutableURLRequest requestWithURL:theURL];
    … construct request …

    NSURLConnection* theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];

    // Only works if I have this following spin loop
    conditional = true;
    while(conditional) {     
        [[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]];
    }
    if (!theConnection) std::cerr << "Connection to feedback failed
";
}

最后一项职能“-(避免)上载数据:NSData*”是我提出问题的。 它不会在没有缝.的情况下工作。 有什么想法?

我补充说,保留了《民族权利倡议》和《民族权利倡议》,因此我认为,在请求没有被复制的情况下,它不是一个种族条件。

EDIT: I feel like these might be a similar issues: NSURLConnection - how to wait for completion and Asynchronous request to the server from background thread however my object (UploadFunc) still exists even after the function finishes and goes out of scope...

问题回答

捐款按拖欠方式管理。 该框架可将其他运行的循环源置于缺省模式之下,如果你打算只处理,就会火上。 诚然,框架应当把其他来源安排在背景线索上,这是不寻常的,但你可以肯定。

运行坡道不应 bus忙。 如果数据比你能够处理得更快,那么你就不必spi忙使用邮袋。 似乎忙.的是,我怀疑存在另一个按违约模式排列的循环源。

表格, 采用私人经营方式(对你所独有的任何任意扼杀加以解释),然后以这种方式管理跑道。 您可以将NSURLConnection与-initWithRequest:delegate:startImmediately:通过NO,用于最后的论点,以避免在违约模式中安排时间。 然后使用<条码>附表:forMode:,以私人方式安排。





相关问题
Undefined reference

I m getting this linker error. I know a way around it, but it s bugging me because another part of the project s linking fine and it s designed almost identically. First, I have namespace LCD. Then I ...

C++ Equivalent of Tidy

Is there an equivalent to tidy for HTML code for C++? I have searched on the internet, but I find nothing but C++ wrappers for tidy, etc... I think the keyword tidy is what has me hung up. I am ...

Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

typedef ing STL wstring

Why is it when i do the following i get errors when relating to with wchar_t? namespace Foo { typedef std::wstring String; } Now i declare all my strings as Foo::String through out the program, ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

Window iconification status via Xlib

Is it possible to check with the means of pure X11/Xlib only whether the given window is iconified/minimized, and, if it is, how?

热门标签