Solved

How to get a new created person ID?

Posted on 2013-02-07
4
672 Views
Last Modified: 2013-02-13
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!
0
Comment
Question by:zc2
  • 2
  • 2
4 Comments
 
LVL 33

Accepted Solution

by:
pgnatyuk earned 500 total points
ID: 38867505
>Basically I call ABRecordRef person = ABPersonCreate(); then populate the properties, etc.

You didn't mention ABAddressBookAddRecord and ABAddressBookSave. I think, this is the error.
0
 
LVL 18

Author Comment

by:zc2
ID: 38886181
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?
0
 
LVL 18

Author Closing Comment

by:zc2
ID: 38886254
Finally I've made that work properly. Was good to know it's possible after all, thank you!
0
 
LVL 33

Expert Comment

by:pgnatyuk
ID: 38887886
You are welcome
0

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I recently went through the process of creating an installable image of an iPhone mobile app (an .ipa file) that beta testers could load onto their test devices. The process involved quite a few steps, but both Appcelerator and Diawi.org had decent …
When Apple released Swift last year, the aim was to introduce a new programming language for Cocoa and Cocoa Touch that was fast, easy and effective, like the name connotes. Apple succeeded. Swift is designed to couple with Objective-C program…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question