As everyone knows that we can create an address book (ABAddressBook), copy all the people into an array and then create a link to the record (ABRecordRef), and 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, with a universal fact, but in my case (application) I have a small problem that if the user first saves the contact and does not add / does not load any image, and then for a while, we get access to the image data from this contact, we have empty images, so I give or assign a default image. But what if the user uploads the image for the contact later or changes the existing one for the contact, which means the updated image will not look as expected, and therefore we cannot rely on the address book name or any index, etc.
Therefore, I had the idea to save the unique identifier of the contact, and then get the contact image based on its identifier. In this process, I saved the unique identifier of the contact in the database, now what's next, holding the id value using the model class, and then save the model class in an array.
This is a sample code to understand:
ReminderClass *reminderToDisplay = [self.remindersArray objectAtIndex:indexPath.row]; NSString *contactIDString = reminderToDisplay.contactID; int addressIndex = [contactIDString integerValue];
Now that we are aware of the fact that we can have an instance of ABRecordRef and thus copy its image data, but as we know, the syntax will be like this:
ABRecordRef personID = CFArrayGetValueAtIndex(CFArrayRef theArray, CFIndex idx);
In any case, I can assign addressIndex instead of CFIndex idx
But I am struck by part of the array, i.e. CFArrayRef , since I have an NSMutableArray containing all id data, i.e. remindersArray
Now I was looking for casting methods from NSMutableArray to CFArrayRef
But I found several questions in different ways, here you can consider an example of a question
Please help me if there is any way to overcome this so that I can access the appropriate images for the respective contacts. Any help is much appreciated!
Thanks to everyone in advance :)