당신은 블록 다운로드
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]];
}];
응용 프로그램이 백그라운드에있을 때 작동합니다. @Sunny shah –
아니요 백그라운드 모드에서 작동하지 않을 때 백그라운드 모드에서 작동합니다. –
앱이 배경에있을 때 이런 종류의 기능을 구현하는 방법 –