2013-03-28 3 views
0

У меня есть файл pdf с сервера.Записать файл в каталог NSDocument показать UIProgressView в iPhone?

Затем мне нужно загрузить файл в путь каталога NSDocument и его работу отлично, но я хочу показать UIProgressView для хранения каждого байта. Как это сделать, пожалуйста, помогите мне

Заранее спасибо

Я пытался сохранить, как это:

  NSError *error; 
      NSArray *ipaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
      NSString *idocumentsDir = [ipaths objectAtIndex:0]; 
      NSString *idataPath = [idocumentsDir stringByAppendingPathComponent:@"File"]; 
      NSLog(@"idataPath:%@",idataPath); 

      //Create folder here 
      if (![[NSFileManager defaultManager] fileExistsAtPath:idataPath]) 
      { 
       [[NSFileManager defaultManager] createDirectoryAtPath:idataPath withIntermediateDirectories:NO attributes:nil error:&error]; 
      } 
    // Image Download here 
      NSString *fileName = [idataPath stringByAppendingFormat:@"/image.jpg"]; 
      NSLog(@"imagePathDOWNLOAD:%@",fileName); 

      NSData *pdfData1 = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:[URLArray objectAtIndex:a]]]; 
      [pdfData1 writeToFile:fileName atomically:YES]; 
+0

Требуется прогресс при загрузке с веб-адреса или при хранении в документах? – Vedchi

+0

при хранении в документах – SampathKumar

ответ

0

Вы можете использовать класс NSURLConnection реализовать прогресс бар:

.h: 
NSMutableData *responseData; 
NSString *originalFileSize; 
NSString *downloadedFileSize; 

.m: 
- (void)load { 
    NSURL *myURL = [NSURL URLWithString:@""]; 
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:myURL 
               cachePolicy:NSURLRequestReloadIgnoringLocalCacheData 
             timeoutInterval:60]; 

[[NSURLConnection alloc] initWithRequest:request delegate:self]; 
} 

- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response { 
responseData = [[NSMutableData alloc] init]; 
originalFileSize = [response expectedContentLength]; 
} 

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data { 
[responseData appendData:data]; 

downloadedFileSize = [responseData length]; 
progressBar.progress = ([originalFileSize floatValue]/[downloadedFileSize floatValue]); 
} 

- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error { 
[responseData release]; 
[connection release]; 

} 

- (void)connectionDidFinishLoading:(NSURLConnection *)connection 
{ 
NSLog(@"Succeeded! Received %d bytes of data",[responseData lengtn]); 

} 

Дайте мне знать для любых запросов.

 Смежные вопросы

  • Нет связанных вопросов^_^