zc2
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!
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Finally I've made that work properly. Was good to know it's possible after all, thank you!
You are welcome
ASKER
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?