簡體   English   中英

如何使用Dropbox Sync API iOS SDK從Dropbox下載文件

[英]How to download file from dropbox using Dropbox Sync API iOS SDK

我正在使用Dropbox Sync API sdk,它顯示所有文件夾和文件,但我們無法下載文件,我正在使用此代碼:

  DBFilesystem *filesystem;
  DBFile *file = [_filesystem openFile:info.path error:nil];
   NSData *imagedata=[file readData:nil];
  [fileMan createFileAtPath:Image_filePath  contents:**data** attributes:nil];
  NSLog(@"flao=%d",[file writeData:imagedata error:nil]);
  // it return 1

我正在獲取NSData,但無法存儲在文檔目錄中。 我檢查以下鏈接,但未成功

Dropbox Sync API iOS將文件復制到應用程序文檔

與DropBox API和iOS進行數據同步

請幫我。

Dropbox緩存文件需要花費時間,您可以設置一個塊來監視緩存何時完成:

__block MyViewController *me = self;
[self.dropboxFile addObserver:self block:^() { [me monitorDropboxFile:@"Sync"]; }];

在觀察者內部:

- (void)monitorDropboxFile:(NSString *)caller
{
    if (self.dropboxFile.status.cached) {
        ; // Good to go, the file is cached
    } else {
        ; // download in progress
    }
}

或者,有一種更簡單的方法,使用readHandle

(DBFile *)file;
// ...  
DBError *dbError;
NSFileHandle *fileHandle = [file readHandle:&dbError];

如Dropbox API標頭中所述:

/ **返回文件的只讀文件句柄。 如果未緩存文件,則該方法將阻塞,直到下載文件為止。
@return如果可以讀取文件,則為文件句柄;如果發生錯誤,則為nil * /

返回時文件句柄已准備就緒。 但是,如果應用程序必須在文件下載期間響應,則您可能希望將readHandle放在后台線程中。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM