Asleepace Asleepace - 2 months ago 15
iOS Question

iOS Save file to non-private directory

Right now I am working on a project which uploads files from the system and I was wondering if it is possible to save NSData to a location that is not private. Basically when I save data right now the cooresponding url looks something like this:

file:///private/var/mobile/Containers/Data/Application/.../image.jpg


But when I get files back from the UIImagePicker the URL looks like this:

file:///var/mobile/Containers/Data/Application/.../image.jpg


How can I (if it is possible) save data to a directory not under private?

Just for reference this is the code I have to move files so far:

- (NSURL *)moveFileToTemporaryMemory:(NSURL *)url {
NSError *readingError, *writingError;
NSString *fileName = url.lastPathComponent;
NSURL *tempURL = [[NSURL fileURLWithPath:NSTemporaryDirectory()] URLByAppendingPathComponent:fileName];
NSData *data = [NSData dataWithContentsOfURL:url options:NSDataReadingMappedIfSafe error:&readingError];
[data writeToURL:tempURL options:NSDataWritingAtomic error:&writingError];
return tempURL;
}

Answer Source

There's no difference -- /var is a symbolic link to /private/var, so both paths are equivalent.