Post not yet marked as solved
Click to stop watching this thread.
You have stopped watching this post. Click to start watching again.
Post marked as unsolved with 5 replies, 0 views
@eskimo The file I'm trying to access is a custom file (created with UIDocument and NSFileWrapper) from another applications of mine. I added the support to this new app I'm developing to open those files, but even through the "open in" functionality directly from File app I get always the same error. I checked the code of the other project but I don't see any restriction created directly by me. From the other app I can zip and export the file, in that case my new app can open the exported file without any issue.
There is something I'm missing or that I'm not aware of?
Here there is the code from the other project, this is from the UIDocument subclass:
(BOOL)loadFromContents:(id)contents ofType:(NSString *)typeName error:(NSError *__autoreleasing *)outError{
_fileWrapper = (NSFileWrapper*)contents;
// The rest will be lazy loaded inside getter methods
return YES;
}
(id)contentsForType:(NSString *)typeName error:(NSError *__autoreleasing *)outError{
if (_fileWrapper == nil) {
NSLog(@"NIL WRAPPER");
_fileWrapper = [[NSFileWrapper alloc]initDirectoryWithFileWrappers:nil];
}
NSDictionary *fileWrappers = [_fileWrapper fileWrappers];
[self encodeString:_name forKey:kName insideDictionary:fileWrappers];
		//all other property of the document
return _fileWrapper;
}
//pragma mark - HELPERs
(void)encodeString:(NSString*)string forKey:(NSString*)key insideDictionary:(NSDictionary*)wrapperDic{
if (([wrapperDic objectForKey:key] == nil) && (string != nil)) {
NSData *textData = [string dataUsingEncoding:NSUTF8StringEncoding];
NSFileWrapper *textFileWrapper = [[NSFileWrapper alloc] initRegularFileWithContents:textData];
[textFileWrapper setPreferredFilename:key];
[_fileWrapper addFileWrapper:textFileWrapper];
}
}
(void)encodeData:(NSData*)imageData forKey:(NSString*)key insideDictionary:(NSDictionary*)wrapperDic{
if (([wrapperDic objectForKey:key] == nil) && (imageData != nil)) {
@autoreleasepool {
NSFileWrapper *imageFileWrapper = [[NSFileWrapper alloc] initRegularFileWithContents:imageData];
[imageFileWrapper setPreferredFilename:key];
[_fileWrapper addFileWrapper:imageFileWrapper];
}
}
}