2012-10-03 26 views

回答

2

我的答案假定您正在討論顯示正在複製的單個文件的進度。

是的,「FSCopyObjectAsync」已被棄用,但它還沒有消失。

正如你所發現的,蘋果還沒有提供有用的替代功能,最終將被刪除。我懷疑(但不確定)當新功能進入時(可能是10.9),它將以「NSFileManagerDelegate」協議發送供代表使用。

爲了確保這一點,Apple需要知道有很多開發人員需要這樣做。在http://bugreporter.apple.com處提交錯誤報告 - 它可能會作爲重複項被關閉,但每個投票都很重要。

+1

錯誤ID#12420342 –

2

copyfile(3)是FSCopyObjectAsync的替代方案。 Here是具有進度回調的複製文件(3)的示例。

+0

沒有UI顯示的CopyFile FUNC – LIUB

0

複製文件與progressIndicator用C

#define BUFSIZE (64*1024) 

void *thread_proc(void *arg); 
     { 
      //outPath & inPatn an NSString paths 

      char buffer[BUFSIZE]; 
      const char * outputFile = [outPath UTF8String]; 
      const char * inputFile = [inPath UTF8String]; 
      int in = open(inputFile, O_RDONLY); 
      int out = open(outputFile, O_WRONLY | O_CREAT | O_TRUNC); 

      vvolatile off_t progress; 
      progress = 0;    
      ssize_t bytes_read; 
      double fileSize = 0; 
      NSNumber * theSize; 

      if ([inPath getResourceValue:&theSize forKey:NSURLFileSizeKey error:nil]) 
        fileSize = [theSize doubleValue]; 

      [progressIndicator setMaxValue:fileSize];  
      while((bytes_read = read(in, buffer, BUFSIZE)) > 0) 
      { 
       write(out, buffer, BUFSIZE); 
       progress += bytes_read; 

       [progressIndicator setDoubleValue:progress]; 

      } 
      // copy is done, or an error occurred 
      close(in); 
      close(out); 
     } 
0

我創建了一個開源項目,解決這個問題,我(3)上的NSOperation包裹複製文件並創建了一個圖形用戶界面,請檢查出來,也許有助於使其更好。

https://github.com/larod/FileCopyDemo

enter image description here

相關問題