在后台应用程序时上传文件:带有 Phonegap 的 ASIHTTPRequest
我正在使用 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
I am using the ASIFormDataRequest 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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
http://allseeing-i.com/ASIHTTPRequest/How-to-use#background_downloads_ios 表明您可以使用:
http://allseeing-i.com/ASIHTTPRequest/How-to-use#background_downloads_ios states that you can use: