I can download and save a binary file to the 'Documents' folder with a custom name perfectly fine.
If I just change the URL to the 'Application Support' folder instead of the 'Documents' folder, it fails to write to that URL saying it doesn't exist.
Here's the URL construction code:
- ( NSURL * ) getSaveFolder
NSURL * appSupportDir = nil;
NSURL * appDirectory = nil;
NSArray * possibleURLs = [[NSFileManager defaultManager] URLsForDirectory:NSApplicationSupportDirectory inDomains:NSAllDomainsMask];
if ( [possibleURLs count] >= 1 )
appSupportDir = [possibleURLs objectAtIndex:0];
if ( appSupportDir != nil)
NSString * appBundleID = [[NSBundle mainBundle] bundleIdentifier];
appDirectory = [appSupportDir URLByAppendingPathComponent:appBundleID];
- ( void ) writeOutDataToFile:( NSData * )data
NSURL * finalURL = [self.rootPathURL URLByAppendingPathComponent:self.aFileName];
[data writeToURL:finalURL atomically:YES];
NSArray * possibleURLs = [[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask];
Documents directory, the
Application Support directory does not exist in the app's sandbox by default. You need to create it before you can use it.
And a much simpler way to get a reference to the directory is:
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES); NSString *appSupportDirectory = [paths objectAtIndex:0];