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