After I select a photo with the camera I’m saving it as NSData. This takes a while and I dont want my users to wait for it. I want it to happen at the background. My question is whether it is wise to perform methods after I call “dismissModalViewControllerAnimated:NO“.
this is my code, which outputs the following:
debug1
debug2
debug4
debug5
debug6
debug3
- (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
// Access the uncropped image from info dictionary
UIImage *image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
NSLog(@"debug1");
// Save image in the normal photo album
UIImageWriteToSavedPhotosAlbum(image, self, @selector(image:didFinishSavingWithError:contextInfo:), nil);
NSLog(@"debug2");
[[MySingleton sharedSingleton] addImg:image];
NSLog(@"debug3");
[picker dismissModalViewControllerAnimated:NO];
[_delegate startStep2];
}
-(void) addImg: (UIImage *) img {
NSLog(@"debug4");
NSData *jpegData = UIImageJPEGRepresentation([img rotateAndScaleFromCameraWithMaxSize:1500.0], 0.9f);
NSLog(@"debug5");
image = [[NSData alloc] initWithData:jpegData];
NSLog(@"debug6");
}
Can I dismiss the viewcontroller first and than do other stuff, or isnt that a good way?
edit// I did solve the waiting problem by doing this:
[[MySingleton sharedSingleton] performSelectorInBackground:@selector(addImg:) withObject:image];
[[MySingleton sharedSingleton] performSelectorInBackground:@selector(addImg:) withObject:image];
did the trick..