我有一个使用基于NSFileWrapper的UIDocument的应用。我的文件包装器是一个名为“XXX.cp”的目录,有两个子文件“photo.data”和“photo.metadata”。它似乎可以保存和加载文档,但是当我转到Settings \ Manage Storage \ Unknown时,子文件会单独列出:
我希望它显示“XXX.cp”而不是这两个子文件。我想我已经正确设置和导出了文档UTI:
我认为我正在创建文件包装器(特别是因为它读/写正常):
- (void)encodeObject:(id<NSCoding>)object toWrappers:(NSMutableDictionary *)wrappers preferredFilename:(NSString *)preferredFilename {
@autoreleasepool {
NSMutableData * data = [NSMutableData data];
NSKeyedArchiver * archiver = [[NSKeyedArchiver alloc] initForWritingWithMutableData:data];
[archiver encodeObject:object forKey:@"data"];
[archiver finishEncoding];
NSFileWrapper * wrapper = [[NSFileWrapper alloc] initRegularFileWithContents:data];
[wrappers setObject:wrapper forKey:preferredFilename];
}
}
- (id)contentsForType:(NSString *)typeName error:(NSError *__autoreleasing *)outError {
if (self.captionedPhotoMetadata == nil || self.captionedPhoto == nil) {
*outError = [[NSError alloc] initWithDomain:CaptionedPhotoErrorDomain code:CaptionedPhotoInvalidDocument userInfo:[NSDictionary dictionaryWithObjectsAndKeys:NSLocalizedString(@"Invalid document!", @""), NSLocalizedDescriptionKey, nil]];
return nil;
}
NSMutableDictionary * wrappers = [NSMutableDictionary dictionary];
[self encodeObject:self.captionedPhotoMetadata toWrappers:wrappers preferredFilename:METADATA_FILENAME];
[self encodeObject:self.captionedPhoto toWrappers:wrappers preferredFilename:DATA_FILENAME];
NSFileWrapper * fileWrapper = [[NSFileWrapper alloc] initDirectoryWithFileWrappers:wrappers];
return fileWrapper;
}
但仍然没有雪茄。谁知道问题是什么?谢谢!
答案 0 :(得分:4)
想出来了。问题是你需要有3个字母的文件扩展名。我只有两个字母:“。ct”。我将其切换为“.cap”并且有效:P
答案 1 :(得分:1)
我没有将我的UTI改为三个字符。它仍然是11个字符。起初我看到了Ray报道的同样问题。我查看了更多文档,并在“iOS应用程序编程指南” - “声明应用程序支持的文档类型”段落下的“应用程序相关资源”中找到“对于每种文档类型,您必须至少提供以下信息:
我提供了名称和文件类型,但没有提供图标。所以我在22秒内制作了最棒的小文档图标,将其添加到我的项目中,将其添加到Target的文档类型,在我的iPad上,设置,iCloud,管理存储,MyApp,我只看到文件包装器name,NSMetadataItemDisplayNameKey style!
答案 2 :(得分:0)
我有同样的问题,但我的扩展有三个字符,我也有一个图标。但是,在阅读this comment后,我尝试删除 CFBundleDocumentTypes 部分中的 LSItemContentTypes (“Types:com.razeware.captionedPhoto”,位于“文档”下的第二张图片中类型“),它的工作原理。
我还注意到WWDC演示“UIDocument和iCloud”也没有设置LSItemContentType。 对我来说似乎是一个巨大的错误,因为the docs明确指出应该有一个文档类型。