9

I have an app that uses a UIDocument that is NSFileWrapper based. My file wrapper is a directory named "XXX.cp", with two sub-files "photo.data" and "photo.metadata". It seems to save and load documents fine, however when I go to Settings\Manage Storage\Unknown the sub-files are listed separately:

Settings

I was expecting it to show "XXX.cp" instead of these two sub-files. I think I have the document UTI set up and exported properly:

UTI UTI Export

And I think I am creating the file wrappers correctly (especially since it reads/writes fine):

- (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;        
}

But still no cigar. Anyone know what the problem is? Thanks!

4

3 回答 3

5

想通了。问题是您需要有 3 个字母的文件扩展名。我的只有 2 个字母:“.cp”。我将它切换到“.cap”并且它起作用了:P

于 2012-04-23T13:25:39.500 回答
1

我没有将我的 UTI 更改为三个字符。它仍然是 11 个字符。起初,我看到了 Ray 报告的相同问题。我查看了更多文档,并在“声明您的应用程序支持的文档类型”段落下的“iOS 应用程序编程指南”-“应用程序相关资源”中找到“对于每种文档类型,您必须至少提供以下信息:

  • 一个名字
  • 一个图标
  • 文件类型

我提供了名称和文件类型,但没有提供图标。因此,我在 22 秒内创建了最棒的小文档图标,将其添加到我的项目中,将其添加到目标的文档类型中,然后在我的 iPad、设置、iCloud、管理存储、MyApp 上,我只看到文件包装器名称,NSMetadataItemDisplayNameKey 样式!

于 2012-06-16T01:08:15.767 回答
0

我有同样的问题,但我的扩展有三个字符,我也有一个图标。但是,在阅读此评论后,我尝试删除CFBundleDocumentTypes部分中的LSItemContentTypes(“文档类型”下的第二张图像中的“类型:com.razeware.captionedPhoto”)并且它起作用了。

我还注意到 WWDC 演示“UIDocument 和 iCloud”也没有设置 LSItemContentType。对我来说似乎是一个巨大的错误,因为文档明确指出应该有一个文档类型。

于 2013-02-20T22:38:31.760 回答