Access contact image from address book based on its id
Asked Answered
L

1

0

As every one is aware of the fact that we can create an address book(ABAddressBook),copy all people in array and then create a record reference(ABRecordRef),then copy its image data using NSData as follows:

ABAddressBookRef addressBook = ABAddressBookCreate( );
CFArrayRef allPeople = ABAddressBookCopyArrayOfAllPeople( addressBook );
ABRecordRef recordReference = CFArrayGetValueAtIndex(allPeople, addressIndex);
NSData *imageData = (NSData *)ABPersonCopyImageData(recordReference);

Now this works fine as expected to be a universal fact,but in my case(application),I have a tiny problem,what if the user saves a contact initially and doesn't add/upload any image,then at the time,we are accessing the image data from that contact,we are having empty image,thus I give or assign a default image.But what if the user uploads image for a contact later on or modifies an existing for a contact,which means the updated image will not appear as expected and thus we can't rely on address book name or some index etc..

Hence I came up with an idea of saving the unique contact id,then get the contact image based on its id.In the process I have saved the unique contact id in to database,now what next,holding the id value using model class,then saving that model class in to array.

This is the sample code for understanding:

ReminderClass *reminderToDisplay = [self.remindersArray objectAtIndex:indexPath.row];
NSString *contactIDString = reminderToDisplay.contactID;
int addressIndex = [contactIDString integerValue];

Now as we are aware of the fact that we can have an instance of ABRecordRef and thus copy its image data,but as we know it's syntax would be:

ABRecordRef personID = CFArrayGetValueAtIndex(CFArrayRef theArray, CFIndex idx);

Any way I can assign addressIndex in the place of CFIndex idx

But I am struck with the array part,i.e. CFArrayRef,as I have an NSMutableArray holding all the id details,i.e. remindersArray

Now I have searched for type casting methods from NSMutableArray to CFArrayRef

But found a few questions on vice-versa,a sample question can be seen over here

Please guide me if there is any way to get over this,so that I can gain access to proper images for respective contacts,Any help is greatly appreciated!

Thanks all in advance :)

Louisalouisburg answered 20/7, 2012 at 7:10 Comment(0)
L
0

Please find the best solution by Mr.HRM from the below link:

https://mcmap.net/q/1322016/-access-contact-image-from-address-book-based-on-name

This definitely would assist you the right way,thanks :)

Louisalouisburg answered 12/3, 2013 at 11:27 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.