1

我需要向用户显示 Dropbox 中所有照片的列表,并提供使用它们的可能性(在项目中下载)。像用户从他的相册中挑选照片一样简化。我正在使用 Dropbox SDK v1.3.3。

更新:

这是我到目前为止所做的:

- (void)restClient:(DBRestClient *)client loadedMetadata:(DBMetadata *)metadata {
    if (metadata.isDirectory) {
        // Available files extensions
        NSArray *validExtensions = [NSArray arrayWithObjects:@"jpg", @"jpeg", @"png", nil];
        // Local path
        NSArray *libraryPaths = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES);
        NSString *LibraryDirectory = [libraryPaths objectAtIndex:0];
        LibraryDirectory = [LibraryDirectory stringByAppendingString:@"/Dropbox/"];
        NSString *localPath = @"";

        if (![[NSFileManager defaultManager] fileExistsAtPath:LibraryDirectory]){
            NSError* error;
            if(  [[NSFileManager defaultManager] createDirectoryAtPath:LibraryDirectory withIntermediateDirectories:NO attributes:nil error:&error])
                ;// success
            else {
                NSLog(@"[%@] ERROR: attempting to write create Dropbox directory", [self class]);
                NSAssert( FALSE, @"Failed to create directory maybe out of disk space?");
            }
        }
        // Work with dropbox files array
        for (DBMetadata *file in metadata.contents) {
            NSString* extension = [[file.path pathExtension] lowercaseString];
            if(![file isDirectory] && [validExtensions indexOfObject:extension]!=NSNotFound) {
                localPath = [LibraryDirectory stringByAppendingPathComponent:[file filename]];
                // Add file to Dropbox Directory
                BOOL fileExists = [[NSFileManager defaultManager] fileExistsAtPath:localPath];
                if(!fileExists) [[self restClient] loadFile:file.path intoPath:localPath];
            }
        }
    }
}

刚刚离开显示来自 Dropbox 本地文件夹的照片列表。也许有人知道该怎么做?我希望它像相册中的那样:

- (void)getDropboxPhotoList:(NSString *)path {
    UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
    /* source must be not from gallery, but from local folder */
    //imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
    imagePicker.delegate = self;

    UIPopoverController *pop = [[UIPopoverController alloc] initWithContentViewController:imagePicker];
    [pop presentPopoverFromBarButtonItem:(UIBarButtonItem *)dropboxButton permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
    popover = pop;
    [imagePicker release];
}
4

1 回答 1

1

Dropbox API显示了一些示例代码,用于列出给定文件夹中的文件:

列出文件夹中的文件

列出文件夹中的文件您可以使用以下调用列出刚刚上传到的文件夹中的文件:

[[self restClient] loadMetadata:@"/"];

其余客户端将使用以下回调之一调用您的委托:

- (void)restClient:(DBRestClient *)client loadedMetadata:(DBMetadata *)metadata {
    if (metadata.isDirectory) {
        NSLog(@"Folder '%@' contains:", metadata.path);
    for (DBMetadata *file in metadata.contents) {
        NSLog(@"\t%@", file.filename);
    }
    }
}

- (void)restClient:(DBRestClient *)client
    loadMetadataFailedWithError:(NSError *)error {

    NSLog(@"Error loading metadata: %@", error);
}

元数据对象是您获取用户 Dropbox 中文件和文件夹信息的方式。调用 loadMetadata: on / 将加载根文件夹的元数据,并且由于它是一个文件夹,因此 contents 属性将包含该文件夹中包含的文件和文件夹的列表。建议保留此数据,以便下次您想对文件执行某些操作时,可以将其当前元数据与您存储的元数据进行比较,以辨别文件是否已更改。查看 DBMetadata.h 以查看元数据对象拥有的所有信息。

于 2013-01-03T14:04:18.623 回答