1

ABPerson has api to get all "linked" person records.

CFArrayRef ABPersonCopyArrayOfAllLinkedPeople (
   ABRecordRef person
);

What determines the return result of this call (i.e. how are links established)? My goal is to create a new address book record (in code) that is linked to an existing record.

Swany
  • 615
  • 8
  • 14
  • There is no public API to establish your own links. What are you trying to accomplish? I have had success in adding a record with the same first and last name as an existing record and the address book framework automatically linked my new record with the existing record, but this isn't documented anywhere to my knowledge, so I'm not sure how dependable it is. – alivingston Feb 14 '14 at 20:29
  • I am trying to reliably write new data for person selected from ABPeoplePickerNavigationController. Sometimes the ABRecordRef returned after the user selects someone is not writeable (calls to ABRecordSetValue() fail with "could not complete..."). The non writeable records seem to be linked records containing social media profiles (like Facebook). So I was thinking I'd create a new record with the data I want and link it with the person selected. The logic being I could always write a newly created record. I suspect what you say is true. I am hoping that Apple with update this crufty old API. – Swany Feb 16 '14 at 13:31

1 Answers1

3

I've accomplished this by trying to write the information to the ABRecordRef in question, as well as the records linked to it. If writing to all linked records fails for permission (in the case that the only record is a Facebook contact, for example) I created a new record with the same first and last name as the existing record(s) and address book linked them. That behavior isn't documented anywhere, but with out a public method to link contacts, it might be the only option.

alivingston
  • 1,410
  • 1
  • 10
  • 15
  • Unless someone else provides more information to the contrary, we'll assume alivingston is correct and that a link between two or more ABRecords is established "automatically" by having the same first and last name. If anyone can shed more light on the limits of this please share. I am curious to know the mechanism by which this happens. I would hope the ABPersonCopyArrayOfAllLinkedPeople() call is not dynamically doing string comparisons between multiple fields of all records in the address book. – Swany Feb 18 '14 at 14:42
  • 1
    It definitely isn't dynamically returning linked people. I've spent quite some time trying to poke around in the address book to discover various edge cases. You can drill into an address book contact to look at the linked records - if you change a linked records name, they remain linked to their respective records. The only way to unlink them is to put the contacts app into edit mode and tell it to unlink them. So, at some point in time apple is setting up a relationship between ABRecords, and it appears that relationship isn't remove unless explicitly done so by the user. – alivingston Feb 18 '14 at 17:54
  • As of iOS 8.3 I'm unable to reproduce this function. It looks like it's gone entirely :( – Tim Apr 21 '15 at 04:29
  • 1
    @Tim I haven't dug through this again since iOS 8 was released, and a lot of the behavior was undocumented - so not a big surprise if something behind the scenes was changed that broke some of the behavior we were seeing by just poking around. :( – alivingston Apr 21 '15 at 12:43