Hi I was wondering how can I call a method just for one time in application life … My application should download some files from server and I need do it just for one time; I mean mean just one time per installation
here is my method
//Download some images from server and save it into directory
- (void) downloadCovers {
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
[self saveFile:@"mag1" ofType:@"png" fromURL:@"http://myweb.com/mag1.png" inDirectory:documentsDirectory];
}
and this method set images as UIButton BG :
- (void)buttonsBGImage {
UIImage * bgMag1 = [self loadImage:@"mag1" ofType:@"png" inDirectory:[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0]];
[mag1 setBackgroundImage:bgMag1 forState:UIControlStateNormal];
NSLog(@"BG IS SET");
}
Set a flag as a NSUserDefaults key and check for this NSUserDefault value in your downloadCovers method. If it is already set, do nothing, else download files and set the flag to true.
Like so:
Cheers