I want to save the loaded image from server in idle time.I use the following to to save image in iPhone memory.
- (void)saveImage:(UIImage *)image withName:(NSString *)name
{
NSData *data1 = UIImageJPEGRepresentation(image, 1.0);
NSFileManager *fileManager = [NSFileManager defaultManager];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *fullPath = [documentsDirectory stringByAppendingPathComponent:name];
[fileManager createFileAtPath:fullPath contents:data1 attributes:nil];
if (image==nil) {
NSLog(@"Not Saved...:%@",name);
}
}
but when his method called i got halt time….i don’t want that…i want to save image when iPhone is inactive…..can help??
Thanks
You need to do this in the background, using a thread.
If you’re supporting iOS 4.0 only, it’s really easy:
Otherwise, look up the
NSThreaddocumentation, orperformSelectorInBackground:withObject:.