Download image from iCloud Drive iOS objective C

自作多情 提交于 2019-12-25 05:24:26

问题


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.


回答1:


i was able to download images using this

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


来源:https://stackoverflow.com/questions/42809076/download-image-from-icloud-drive-ios-objective-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!