iOS的DropboxSDK,获取远程的子目录和内容 [英] iOS DropboxSDK, get remote subdirectories and contents

查看:530
本文介绍了iOS的DropboxSDK,获取远程的子目录和内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有几个子目录和文件在他们的Dropbox远程目录。

I have a remote directory with several subdirectories and files in them on Dropbox.

远程端:

-Mobile Profiles *(root)*
-- Custom Profiles
--- Profile1
--- Profile2
--- Profile3

上传的文件和目录/和子目录使用文件是没有问题的。我有一个大脑放屁的时候,它会得到从Dropbox的子目录及其内容到设备上。

Uploading the files and directories / and subdirectories with files is not a problem. I am having a brain fart when it comes to getting the subdirectories and their contents from dropbox to the device.

-(void)backupCustomProfiles {
    for ( NSString *file in [[NSFileManager defaultManager] contentsOfDirectoryAtPath:MP_CUSTOM error:&error] ) {
        [self.restClient uploadFile:file toPath:@"/Mobile Profiles/Custom Profiles/" fromPath:EasyStrings(MP_CUSTOM,file)];
    }
}

获得

-(void)restoreCustomProfiles {
    for ( ) {
        /* ? */
    }
}

我不知道如何通过遍历子目录在远程端。

I am not sure how to iterate through the subdirectories on the remote side.

推荐答案

首先加载目录元数据,然后加载它引用的文件。

First load the directory metadata, then load the files that it references.

要限制并行取数,使用NSOperationQueue所有loadMetadata和调用的loadFile限制并行取数。并避免多余的文件下载,记得在plist中下载的元数据。

To limit the number of parallel fetches, use a NSOperationQueue for all of the loadMetadata and loadFile calls to limit the number of parallel fetches. And to avoid redundant file downloads, remember the downloaded metadata in a plist.

- (void) restoreCustomProfiles
{
    [self.client loadMetadata:@"/Mobile Profiles/Custom Profiles" withHash:hash];
}

- (void) restClient:(DBRestClient*)client loadedMetadata:(DBMetadata*)metadata
{
    for (DBMetadata* child in metadata.contents) {
        NSString *path = [child.path lowercaseString];

        if (child.isDirectory) {
            [client loadMetadata:child.path withHash:hash];
        } else {
            [client loadFile:pathToDownload intoPath:[
                                self.directory stringByAppendingString:path]];
        }
    }
}

- (void) restClient:(DBRestClient*)client loadedFile:(NSString*)destPath
{
    // successfully downloaded a file to destPath
}

这篇关于iOS的DropboxSDK,获取远程的子目录和内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆