JohnC
JohnC

Reputation: 221

Store multiple image files in iPad Application

Should I store the multiple image files as NSData to SQLite or
save physical files to Document Folder??

Thanks

Upvotes: 0

Views: 57

Answers (1)

Dheeraj Kumar
Dheeraj Kumar

Reputation: 441

Store the image in the application directory. This is best and easy way to handle. Try the following code. it will be help you.

/Store Image/Songs files to Application Directory
+(BOOL)writeToFile:(NSData *)data fileName:(NSString *)fileName {

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];

// the path to write file
NSString *appFile = [documentsDirectory stringByAppendingPathComponent:fileName];

    return [data writeToFile:appFile atomically:YES];
}
//Image -  Retrieve from Application Directory

+(NSData *)readFromFile:(NSString *)fileName {

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *filePath = [documentsDirectory stringByAppendingPathComponent:fileName];

NSData *myData = [NSData dataWithContentsOfFile:filePath]; 
if (myData) { 
    return myData;
}
return nil;
}

Upvotes: 1

Related Questions