1

I am writing an app that interfaces with the iPhone address book.

Here is the relevant section of my code (from UIImagePickerControllerDelegate)

-(void)imagePickerController:(UIImagePickerController *)picker 
       didFinishPickingImage:(UIImage *)image 
                 editingInfo:(NSDictionary *)editingInfo
{
    ABPersonSetImageData(record, (__bridge CFDataRef)UIImagePNGRepresentation(image), &error);
}

My app lets you take a picture with the camera (using UIImagePictureController), and then stores it as the contact for someone in your address book.

I'm finding that the operation above hangs for 5-10 seconds. 1) Is there a better approach? 2) Why is this so slow?

Matt H.
  • 10,438
  • 9
  • 45
  • 62

1 Answers1

1

Saving as a JPEG:

UIImageJPEGRepresentation (UIImage *image, CGFloat compressionQuality);

will be faster than UIImagePNGRepresentation, especially if compressionQuality is set to a low value. However, this is still a CPU intensive process, so there's no way to avoid the wait.

The best you can do is show a message that work is being done, so the interface doesn't feel unresponsive. Use something like SVProgressHUD to do that.

mopsled
  • 8,445
  • 1
  • 38
  • 40
  • Thanks! It makes me wonder how it gets done so fast in the native Contacts app. I'm guessing a background thread? – Matt H. Jun 25 '12 at 20:22