我是否必须下载所有iCloud文件才能生成缩略图? [英] Do I have to download all iCloud files to be able to generate their thumbnails?

查看:1597
本文介绍了我是否必须下载所有iCloud文件才能生成缩略图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经阅读了有关此错误的堆栈溢出的所有答案,但没有一个解决了这个问题,因为我的问题有点不同。

I have read all answers on stack overflow about this error and none solved the case, because my question is a little different.

我正在枚举iCloud驱动元素 NSMetadataItem 并将它们存储在一个数组上。

I am enumerating iCloud drive elements NSMetadataItem and storing them on an array.

文件在那里:通过查看OS X上的iCloud文件夹来确认并且在设备上使用 UIDocumentPicker

The files are there: confirmed by looking at the iCloud folder on OS X and also on the device using UIDocumentPicker.

稍后在代码中我尝试使用这些元素检索这些元素的缩略图:

Later on the code I try to retrieve the thumbnails of such elements using:

// self.item is a NSMetadataItem
NSURL *fileURL = [self.item valueForAttribute:NSMetadataItemURLKey];

AVAsset *asset = [AVAsset assetWithURL:fileURL];
AVAssetImageGenerator *generator = [[AVAssetImageGenerator alloc] initWithAsset:asset];
generator.appliesPreferredTrackTransform = YES;

CMTime time = CMTimeMakeWithSeconds(1, 60);

AVAssetImageGeneratorCompletionHandler handler = ^(CMTime requestedTime, CGImageRef im, CMTime actualTime, AVAssetImageGeneratorResult result, NSError *error){
  if (result != AVAssetImageGeneratorSucceeded) {
    NSLog(@"couldn't generate thumbnail, error:%@", error);
  }

  // TODO Do something with the image
};

generator.maximumSize = size;
[generator generateCGImagesAsynchronouslyForTimes:@[[NSValue valueWithCMTime:time]]
                                completionHandler:handler];

我在处理程序中收到此错误:

I receive this error inside the handler:

无法生成缩略图,错误:错误Domain = NSURLErrorDomain
Code = -1100在此服务器上找不到请求的URL。
UserInfo = {NSLocalizedDescription =在
此服务器上找不到请求的URL。,NSUnderlyingError = 0x15f82b2a0 {错误
Domain = NSPOSIXErrorDomain Code = 2没有这样的文件或目录}}

couldn't generate thumbnail, error:Error Domain=NSURLErrorDomain Code=-1100 "The requested URL was not found on this server." UserInfo={NSLocalizedDescription=The requested URL was not found on this server., NSUnderlyingError=0x15f82b2a0 {Error Domain=NSPOSIXErrorDomain Code=2 "No such file or directory"}}

问题在于URL,但是,URL是直接从`NSMetadataItem提取的,其格式为

the problem is with the URL, you say, but the URL is extracted directly from the `NSMetadataItem" and has the form


file:/// private / var / mobile / Library / Mobile%20Documents / iCloud~com~myCompany~myApp / Documents / 0%20-% 20intro.mov

file:///private/var/mobile/Library/Mobile%20Documents/iCloud~com~myCompany~myApp/Documents/0%20-%20intro.mov

...在这种情况下,电影名为 0 - intro.mov

...in this case the movie is called 0 - intro.mov

我已经尝试了3种其他方法来下载缩略图。无效。

I have tried 3 other methods to download the thumbnails. None works.

突破

我现在发现我必须下载iCloud驱动器上的所有文件(使用 startDownloadingUbiquitousItemAtURL:错误:)设备能够生成缩略图,看起来很疯狂。想象一下远程视频千兆字节,必须下载所有文件才能显示缩略图。

I have discovered now that I have to download all files that are on iCloud drive (using startDownloadingUbiquitousItemAtURL:error:) to the device to be able to generate their thumbnails, what seems to be insane. Imagine having several gigabytes of videos remotely and having to download all files just to show their thumbnails.

它必须以另一种方式存在。证据是 UIDocumentPicker 显示iCloud上所有视频的缩略图,而不下载它们。

It must exist another way. The proof is that the UIDocumentPicker shows the thumbnails of all videos that are on iCloud without downloading them.

任何线索?

推荐答案

我认为问题是由于在找到URL后读取文件的权限而引起的。但是,根据此答案,您应该能够执行以下操作:

I think the issue is arising due to permissions to read the files after the URL's have been found. Per this answer, however, you should be able to do it with the following:

[url startAccessingSecurityScopedResource];

NSFileCoordinator *coordinator = [[NSFileCoordinator alloc] init];
__block NSError *error;
[coordinator coordinateReadingItemAtURL:url options:0 error:&error byAccessor:^(NSURL *newURL) {
    [newURL getResourceValue:&image forKey:NSURLThumbnailDictionaryKey error:&error];
}];

[url stopAccessingSecurityScopedResource];

这篇关于我是否必须下载所有iCloud文件才能生成缩略图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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