yosh
yosh

Reputation: 3305

iPhone - downloading images to app directory

I could really use some help with files (images) download/save application process.

I need some methods to:

I know how to do it on Android, however on iPhone it seems a bit unclear.

Upvotes: 0

Views: 490

Answers (1)

Amy Worrall
Amy Worrall

Reputation: 16337

Use this code to obtain your application's Documents directory path. This directory is only accessible from your application.

- (NSString *)applicationDocumentsDirectory {

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *basePath = ([paths count] > 0) ? [paths objectAtIndex:0] : nil;
return basePath;
}

To save and load files from there, you can use any of a wide range of methods, from C functions (fopen and the like) to Cocoa convenience methods like NSString's

- (BOOL)writeToFile:(NSString *)path atomically:(BOOL)useAuxiliaryFile encoding:(NSStringEncoding)enc error:(NSError **)error

Upvotes: 2

Related Questions