我有一個應用程序使用基於NSFileWrapper的UIDocument。我的文件包裝器是一個名爲「XXX.cp」的目錄,其中有兩個子文件「photo.data」和「photo.metadata」。這似乎保存和加載文件正常,但是當我去設置\管理存儲\未知子都單獨列出:iCloud&NSFileWrapper:在設置中顯示爲2個不同的文件
我期待它,以示「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;
}
但仍然沒有雪茄。任何人都知道問題是什麼?謝謝!
我也有這個問題,我有3個字母作爲我的文件擴展名。我使用擴展名.tfx作爲我的基於目錄的文件包裝器。我最近決定將我的包裝文件放在我稱爲SyncDocuments的無處不在的容器中的單獨文件夾中。這樣,單個文件就不會顯示給用戶。但這是我真正想要的,因爲我的UIDocument子類文件不適合用戶直接進行交互。 – 2012-04-24 21:24:19
我有完全相同的問題,但我的文件擴展名有三個字母(和一個圖標)。我認爲這是出口UTI中的一些魚腥味。我的預感是,在iCloud中存在某種緩存,並且將擴展名從.cp更改爲.cap修復了一些被破壞的內容。 – auco 2013-02-20 21:35:30
嘿雷愛你的教程,但我仍然有一個問題。我可以讓我的包裝顯示爲包,但然後我的nsmetadataquery沒有看到它們。如果我使用*搜索所有文檔,則不是事件。我的第一個文檔類型工作,但我的圖像不是 – zambono 2013-12-04 00:19:43