小编AMI*_*ekh的帖子

如何在iOS后台模式下载文件?和网络连接丢失

在我的应用程序中,我从服务器下载音频文件,当应用程序在前台时,当我单击主页按钮或锁定按钮强制应用程序转到后台时,文件会正常下载,然后一段时间后,下载是停了,错误来了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)

objective-c nsurlconnection ios

3
推荐指数
1
解决办法
3173
查看次数

标签 统计

ios ×1

nsurlconnection ×1

objective-c ×1