从iCloud Drive iOS目标C下载图像 [英] Download image from iCloud Drive iOS objective C

查看:136
本文介绍了从iCloud Drive iOS目标C下载图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经遍历了许多链接,但对我没有任何帮助.我需要做的就是获取所有iCloud Drive文件并下载图像.我成功使用下面的代码

I have gone through many links, but nothing worked for me. All i need to do is fetch all iCloud Drive files and download images. I succeeded fetching all files using below code

 - (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];
}

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

now i don't know how to proceed further to download image.

推荐答案

我能够使用此下载图像

    #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];
}

这篇关于从iCloud Drive iOS目标C下载图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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