如何使用Dropbox Sync API iOS SDK从Dropbox下载文件 [英] How to download file from dropbox using Dropbox Sync API iOS SDK
问题描述
我正在使用 Dropbox Sync API sdk ,它会显示所有文件夹和文件但是我们不能使用以下代码下载文件
i:
I am using Dropbox Sync API sdk it display all folder and file but we can not download file i am using this code:
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但无法存储在文档中目录。
我检查了以下链接,但没有成功
I am getting NSData but i can't store in document directory. I check below links but no success
Dropbox Sync API iOS将文件复制到应用程序文档
请帮助
推荐答案
Dropbox需要花费时间来缓存文件,您可以设置一个块来监视缓存何时完成:
Dropbox takes time to cache a file, you can set up a block to monitor when the cache is completed:
__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
:
Or, there is a simpler way, use readHandle
:
(DBFile *)file;
// ...
DBError *dbError;
NSFileHandle *fileHandle = [file readHandle:&dbError];
如Dropbox API标头所示:
As documented in the Dropbox API header:
/ **返回文件的只读文件句柄。如果未缓存
文件,则该方法将阻塞,直到下载文件为止。
@return如果可以读取文件,则为文件句柄,否则为 nil
如果发生错误
。 * /
/** Returns a read-only file handle for the file. If the file is not cached then the method will block until the file is downloaded.
@return A file handle if the file can be read, ornil
if an error occurred. */
返回文件句柄已准备就绪。但是,如果应用程序必须在文件下载期间响应,则您可能希望将 readHandle
放入后台线程。
The file handle is ready when returned. However, you might like to put readHandle
in a background thread if the app has to be responsive during file download.
这篇关于如何使用Dropbox Sync API iOS SDK从Dropbox下载文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!