我正在枚举iCloud驱动元素NSMetadataItem并将它们存储在数组中.
文件在那里:通过查看OS X上的iCloud文件夹以及使用UIdocumentPicker的设备进行确认.
稍后在代码中我尝试使用以下方法检索此类元素的缩略图:
// self.item is a NSMetadataItemNSURL *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];
我在处理程序中收到此错误:
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’中提取的,并且具有表单
file:///private/var/mobile/library/Mobile%20documents/iCloud~com~myCompany~myApp/documents/0%20-%20intro.mov
…在这种情况下,电影被称为0 – intro.mov
我已经尝试了3种其他方法来下载缩略图.没有用.
突破
我现在已经发现我必须将iCloud驱动器上的所有文件(使用startDownloadingUbiquitousItemAtURL:error :)下载到设备才能生成缩略图,这似乎是疯了.想象一下,远程拥有几千兆字节的视频,并且必须下载所有文件才能显示缩略图.
它必须以另一种方式存在.证明是UIdocumentPicker显示iCloud上所有视频的缩略图而不下载它们.
有线索吗?
解决方法 我认为问题是由于在找到URL之后读取文件的权限.但是,按照 this answer,您应该可以使用以下内容执行此 *** 作:[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];总结
以上是内存溢出为你收集整理的ios – 我是否必须下载所有iCloud文件才能生成缩略图?全部内容,希望文章能够帮你解决ios – 我是否必须下载所有iCloud文件才能生成缩略图?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)