Link to home
Start Free TrialLog in
Avatar of zc2
zc2Flag for United States of America

asked on

How to get a new created person ID?

Hello,
I'm very new to the iOS programming, so please excuse me if my question is too dumb.
I need to create a contact in the address book, and as soon it's created, I need to know the ID of the new created contact.

Basically I call ABRecordRef person = ABPersonCreate(); then populate the properties, etc.
Then I call ABRecordGetRecordID( person ) to get the contact ID. But it always returns -1 (kABRecordInvalidID). I tried to save the AB and obtain it again, etc. no luck.
I see the new contact has actually been added to the contact list, but how can I obtain it's ID??

The only solution now I could imagine is to calculate the hash of all the properties, and then reopen the AB and search for a contact with the hash value.

Please help!
ASKER CERTIFIED SOLUTION
Avatar of pgnatyuk
pgnatyuk
Flag of Israel image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of zc2

ASKER

Thank you very much for the answer.
I do call ABAddressBookSave(), but I'm not sure about the ABAddressBookAddRecord() function.
At what point should I call it? Right after ABAddressBookSave() ? Before I call ABRecordSetValue() to write the properties or after that?
Avatar of zc2

ASKER

Finally I've made that work properly. Was good to know it's possible after all, thank you!
You are welcome