在使用uidocumentpickerviewcontroller下载到设备上之前,如何在iCloud中找到文档的大小,我可以将文档下载到设备上,然后转换为NSData,我可以确定文件大小,但是我们可以避免下载文档本身并在下载之前预先确定文件大小,在下载.I之前无法在uidocument采集器中找到任何方法或属性。
- (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
}
}发布于 2016-12-06 19:23:07
配置文件协调器,只读取元数据,而不是下载整个file.From --这个url --我们使用getPromisedItemResourceValue: forKey:NSURLFileSizeKey方法获得云中文件的文件大小:
请张贴任何比这个way.This更有效的答案,这是对我有用的解决方案。
- (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);
}
}
}https://stackoverflow.com/questions/40867944
复制相似问题