开发者

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

开发者 https://www.devze.com 2023-02-04 05:55 出处:网络
For the UIImagePickerController, I opened the picker.allowsEditing = YES; so that user can move and scale t开发者_运维技巧he photo, after capturing or selecting from album. Once the \"choose\" or

For the UIImagePickerController, I opened the

picker.allowsEditing = YES;

so that user can move and scale t开发者_运维技巧he 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消