首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在选择文档并使用iCloud下载到设备之前,如何在UIDocumentPickerViewController中找到文档的大小

在选择文档并使用iCloud下载到设备之前,如何在UIDocumentPickerViewController中找到文档的大小
EN

Stack Overflow用户
提问于 2016-11-29 14:09:13
回答 1查看 1.3K关注 0票数 6

在使用uidocumentpickerviewcontroller下载到设备上之前,如何在iCloud中找到文档的大小,我可以将文档下载到设备上,然后转换为NSData,我可以确定文件大小,但是我们可以避免下载文档本身并在下载之前预先确定文件大小,在下载.I之前无法在uidocument采集器中找到任何方法或属性。

代码语言:javascript
复制
 - (void)documentPicker:(UIDocumentPickerViewController *)controller didPickDocumentAtURL:(NSURL *)url {

 NSFileCoordinator *coordinator = [[NSFileCoordinator alloc] initWithFilePresenter:nil];
    NSError *error = nil;

    [coordinator coordinateReadingItemAtURL:url options:0 error:&error byAccessor:^(NSURL *newURL) {

//assuming the file coordinator has downloaded the file here and provided the new url here
}

    }
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-12-06 19:23:07

配置文件协调器,只读取元数据,而不是下载整个file.From --这个url --我们使用getPromisedItemResourceValue: forKey:NSURLFileSizeKey方法获得云中文件的文件大小:

请张贴任何比这个way.This更有效的答案,这是对我有用的解决方案。

代码语言:javascript
复制
- (void)documentPicker:(UIDocumentPickerViewController *)controller didPickDocumentAtURL:(NSURL *)url {
     NSError *error = nil;
    NSFileCoordinator *coordinator = [[NSFileCoordinator alloc] initWithFilePresenter:nil];

     [coordinator coordinateReadingItemAtURL:url options:NSFileCoordinatorReadingImmediatelyAvailableMetadataOnly error:&error byAccessor:^(NSURL *newURL) {

         NSError *err = nil;

         NSNumber * fileSize;
         if(![url getPromisedItemResourceValue:&fileSize forKey:NSURLFileSizeKey error:&err]) {
             NSLog(@"Failed error: %@", error);
             return ;
         } else {
          NSLog(@"fileSize %f",fileSize.doubleValue);
}
}
}
票数 9
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/40867944

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档