0

I need to get the reference URL for the stored image of a contact.

If I'm getting an image from a UIImagePickerController, I can get that simply by doing this.

NSURL *imageURL = [info objectForKey:UIImagePickerControllerReferenceURL];

But how do I get this NSURL for an image of a contact from the Address Book?

UIImage *contactImage = [UIImage imageWithData:CFBridgingRelease(ABPersonCopyImageData(ref))];

i.e. get the reference URL for contactImage.

Sudeep
  • 796
  • 6
  • 16

1 Answers1

0

The ref argument in your question is not an NSURL, but an ABRecordRef, i.e. the reference to an address book record. You had first to open the address book using code like

CFErrorRef error = nil;
ABAddressBookRef addressBookRef = ABAddressBookCreateWithOptions (NULL, &error);

and then to find the required person using e.g.

ABRecordRef ref = ABAddressBookGetPersonWithRecordID (addressBookRef,recordID);  

This gives you the required ref.

Reinhard Männer
  • 14,022
  • 5
  • 54
  • 116
  • I don't think you understood my question, perhaps I was not clear enough. I understand that `ref` is an `ABRecordRef`. My objective is to get the `NSURL` of the contact image obtained from the `ABRecordRef`. – Sudeep May 08 '15 at 08:34
  • Sorry, this was not clear to me. I believe you cannot get such an NSURL. As far as I know, these images are stored in a database, and are not accessible via URLs. – Reinhard Männer May 08 '15 at 08:38
  • I see, are you aware of any alternative? I am using a third-party SDK, which makes use of the `NSURL` to send the image. – Sudeep May 08 '15 at 08:43
  • 1
    Maybe you could save the image to a temp file, use this URL, and delete the file in the callback? I know this is ugly, but I don't have another idea... – Reinhard Männer May 08 '15 at 08:49
  • Yeah I thought of that, guess I'll have to do that for now. Thanks for your help! – Sudeep May 08 '15 at 08:52