Upload File while application in background : ASIHTTPRequest with Phonegap
I am using the ASIFormDataR开发者_C百科equest for uploading file on server.
I am using ASIHTTPRequest to achieve the functionality of upload in background.It working fine. But When application going to background then it fail to upload the file.
I try a lot of test with my code, even sometime it works for background too.
When I am uploading file and application going to background and then application again active then it upload successfully. I notice that (but not sure) if application going in background for time more than the request time out time then it fail to upload. (I am not sure about it)NSString *filePath = [arguments objectAtIndex:0];
NSString *fileName = [arguments objectAtIndex:1];
NSURL *url = [NSURL URLWithString:@"http://192.168.1.107/~amitb/test/upload.php"];
NSData *imageData = [[[NSData alloc] initWithContentsOfFile:filePath] autorelease];
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
request.delegate = self;
[request setData:imageData withFileName:fileName andContentType:nil forKey:@"file"];
[request startAsynchronous];
Can anybody help me to upload file while application in background
Amit Battan
http://allseeing-i.com/ASIHTTPRequest/How-to-use#background_downloads_ios states that you can use:
[request setShouldContinueWhenAppEntersBackground:YES];
精彩评论