简体   繁体   中英

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!!

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];
}

Are you calling the UIImagePicker from the main thread?

This code should be called from there. Every time I have this exact 5 seconds delay on anything UI-related, it is because the code is being called from another thread, instead the main one.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM