Reputation: 179
I'm beginner of iphone app development.I done an iphone app that it contains registration page,login page and profile using sql database as a saving field.I want to keep a pic as profile pic.I done selecting a pic from already stored pics from simulator.I want to keep that pic as it is when once again if I run that....plz help me...
Upvotes: 7
Views: 108
Reputation: 38249
Use this when obtaining image of image selected from gallery by using imagepicker:
-(void)saveImageInDirectoryAndStoreInDatabase
{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory , NSUserDomainMask, YES);
NSString *documentsDir = [paths objectAtIndex:0];
NSString *imgFilePath = [documentsDir stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.png",youruserName];
NSData *data = UIImagePNGRepresentation(youruserImage) //which is obtained from imagepicker
[data writeToFile:imgFilePath atomically:YES];
//query here into database with imageFile(A string) which is[NSString stringWithFormat:@"%@.png",youruserName];
}
Similarly when retrieve image use documentDirectory+imageFile.png (which is obtained from database by querying user name with its imageFile) path to set user profile pic
Upvotes: 0
Reputation: 271
You can store the image in Application bundle and can retrieve the image at the time of application load:
Here is a tutorial for you :
Upvotes: 2