0

我浏览了很多链接,但没有任何对我有用。我需要做的就是获取所有 iCloud Drive 文件并下载图像。我使用以下代码成功获取所有文件

 - (void)presentDocumentPicker {
    NSArray *documentTypes = @[@"public.content", @"public.text", @"public.source-code ", @"public.image", @"public.audiovisual-content", @"com.adobe.pdf", @"com.apple.keynote.key", @"com.microsoft.word.doc", @"com.microsoft.excel.xls", @"com.microsoft.powerpoint.ppt"];


    UIDocumentPickerViewController *documentPickerViewController = [[UIDocumentPickerViewController alloc] initWithDocumentTypes:documentTypes inMode:UIDocumentPickerModeOpen];
    documentPickerViewController.delegate = self;
    [self presentViewController:documentPickerViewController animated:YES completion:nil];
}


#pragma mark - UIDocumentPickerDelegate

- (void)documentPicker:(UIDocumentPickerViewController *)controller didPickDocumentAtURL:(NSURL *)url {
    self.documentURL = url;

    QLPreviewController *previewController = [[QLPreviewController alloc] init];
    previewController.delegate = self;
    previewController.dataSource = self;

    [self.navigationController pushViewController:previewController animated:YES];
}

现在我不知道如何进一步下载图像。

4

1 回答 1

0

我能够使用这个下载图像

    #pragma mark - UIDocumentPickerDelegate
- (void)documentPicker:(UIDocumentPickerViewController *)controller didPickDocumentAtURL:(NSURL *)url {
    self.documentURL = url;


    NSNumber *isDownloadedValue = NULL;

    BOOL success = [url getResourceValue:&isDownloadedValue forKey: NSURLUbiquitousItemIsDownloadingKey error:NULL];

    if (success && ![isDownloadedValue boolValue]) {
        [[NSFileManager defaultManager]startDownloadingUbiquitousItemAtURL:url error:nil];

        // load image from Ubiquity Documents directory
        NSData *imageData = [NSData dataWithContentsOfURL:url];
           UIImage *     image = [UIImage imageWithData:imageData];
    }

    QLPreviewController *previewController = [[QLPreviewController alloc] init];
    previewController.delegate = self;
    previewController.dataSource = self;

    [self.navigationController pushViewController:previewController animated:YES];
}
于 2017-03-17T04:54:09.280 回答