我正在调查AFNetworking作为替代品ASIHTTPRequest,并注意到它是否支持后台下载/上传完全缺乏信息.
使用ASIHTTPReqeust对象,您所要做的就是调用[request setShouldContinueWhenAppEntersBackground:YES],请求将在后台继续.这有什么支持AFNetworking吗?
我可以在后台进行应用程序处理,还是只是处于休眠状态直到它被带到前台?我可以让它发出http请求吗?
在我的应用程序中,我从服务器下载音频文件,当应用程序在前台时,当我单击主页按钮或锁定按钮强制应用程序转到后台时,文件会正常下载,然后一段时间后,下载是停了,错误来了1005 network connection lost.有什么问题?任何人都可以解释这个问题吗?
码:
NSURL *url = [NSURL URLWithString:currentURL];
NSURLRequest *theRequest = [NSURLRequest requestWithURL:url cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:60];
receivedData = [[NSMutableData alloc] initWithLength:0];
NSURLConnection * connection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self startImmediately:YES];
myConnection = connection;
NSLog(@"%@ Download Started", currentURL);
- (void) connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
[receivedData setLength:0];
expectedBytes = [response expectedContentLength];
}
- (void) connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
[receivedData appendData:data];
float progressive = (float)[receivedData length] / (float)expectedBytes;
[downloadProgressView setProgress:progressive];
NSInteger val = progressive*100; …Run Code Online (Sandbox Code Playgroud)