在后台应用程序时上传文件:ASIHTTPRequest with Phonegap

时间:2011-10-11 13:27:03

标签: iphone cordova asihttprequest asiformdatarequest

我使用ASIFormDataRequest在服务器上上传文件 我正在使用ASIHTTPRequest来实现后台上传的功能。

工作正常。但是当应用程序进入后台时,它无法上传文件。

我用我的代码尝试了很多测试,甚至有时它也适用于背景。
当我将文件和应用程序上传到后台然后再次激活应用程序时,它会成功上传 我注意到(但不确定)如果应用程序在后台运行时间超过请求超时时间则无法上传。 (我不确定)

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];

任何人都可以帮我在后台申请时上传文件

Amit Battan

1 个答案:

答案 0 :(得分:2)

http://allseeing-i.com/ASIHTTPRequest/How-to-use#background_downloads_ios表示您可以使用:

[request setShouldContinueWhenAppEntersBackground:YES];