Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIImagePickerController's didFinishPickingMediaWithInfo is too slow, can I add progressHUD/indicator?

For the UIImagePickerController, I opened the

picker.allowsEditing = YES;

so that user can move and scale the photo, after capturing or selecting from album. Once the "choose" or "use" is clicked, the whole app is frozen for more than 5 seconds, and then goes back with the photos, through

- (void)imagePickerController:(UIImagePickerController*)picker
didFinishPickingMediaWithInfo:(NSDictionary *)info

I tried to add an indicator in this delegate function, but it doesn't appear... I guess, the long delay happens before this callback, and is probably because of the "editing" from ful

Is there any possible way to handle this? I just wish to give the users a good experience. :)

Thanks a lot!!

like image 714
Dobby Avatar asked Jan 16 '11 04:01

Dobby


1 Answers

You should perform this on another thread and with an NSAutoreleasePool, like so:

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo {
   [self.navigationController dismissModalViewControllerAnimated:YES];   
   [NSThread detachNewThreadSelector:@selector(uploadImage:) toTarget:self withObject:image];  
}

- (void)uploadImage:(UIImage *)image {
   NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
   // Handle chosen photo
   [pool release];
}
like image 111
Kolin Krewinkel Avatar answered Sep 20 '22 00:09

Kolin Krewinkel