2

배경 및 업데이트에 대응 progressview에 배수 파일을 다운로드하고 그것을 잘 나누었다 작동되는 방법 내가 업로드 한 이미지.나는 등, 여러 파일을 다운로드해야 내가 .. 난 보았 <a href="https://github.com/ncipollina/nsurlsession-sample" rel="nofollow noreferrer">this</a></p> <p>링크를 배경 파일을 다운로드 NSURLSession을 사용하고

어떻게 이것을 달성하기 위해, 모든 조언을 매우 높이 평가 될 것입니다.

enter image description here

답변

1

당신은 블록 다운로드

typedef void (^onDownload)(NSData *data); 
typedef void (^onDownloadProgress)(id,id); 

@property (nonatomic,retain) onDownload block; 
@property (nonatomic,retain) onDownloadProgress progressBlock; 

코딩 사용할 수 있습니다

-(void) downloadFileFromURL:(NSURL *)url1 withCompletionBlock:(onDownload)completeBlock withProgressBlock:(onDownloadProgress) pBlock{ 
    self.block = [completeBlock copy]; 
    self.progressBlock = [pBlock copy]; 
    self.url = url1; 
    NSURLConnection *connection = [[NSURLConnection alloc]initWithRequest:[NSURLRequest requestWithURL:url1] delegate:self]; 
    [connection start]; 
} 

-(void)connection:(NSURLConnection *)connection didSendBodyData:(NSInteger)bytesWritten totalBytesWritten:(NSInteger)totalBytesWritten totalBytesExpectedToWrite:(NSInteger)totalBytesExpectedToWrite{ 
      float progress = (totalBytesWritten *100)/totalBytesExpectedToWrite; 
      self.progressBlock(self,[NSNumber numberWithDouble:progress]); 
      //return process 
    } 

요청 URL

FileDownloader *download=[[FileDownloader alloc]init]; 

    [download downloadFileFromURL:url withCompletionBlock:^(NSData *data) { 
     [lblProcess setHidden:YES]; 

     //Compale Dwonloading 

    } withProgressBlock:^(FileDownloader *download,NSNumber* process) { 
     lblProcess.text=[NSString stringWithFormat:@"%.0f%%",[process doubleValue]]; 
    }]; 
+0

응용 프로그램이 백그라운드에있을 때 작동합니다. @Sunny shah –

+0

아니요 백그라운드 모드에서 작동하지 않을 때 백그라운드 모드에서 작동합니다. –

+0

앱이 배경에있을 때 이런 종류의 기능을 구현하는 방법 –