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?
Saving as a JPEG:
will be faster than
UIImagePNGRepresentation, especially ifcompressionQualityis 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
SVProgressHUDto do that.