Solved

How to get a new created person ID?

Posted on 2013-02-07
4
666 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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

In this article I'm going to cover the basics and usages of NSInvocation. What is NSInvocation? Apple Developer Reference describes NSInvocation this way: An NSInvocation is an Objective-C message rendered static, that is, it is an action tur…
CocoaPods is the best way to manage library dependencies in iOS and OS X projects. By using cocoa pods there is no need of downloading the code from github and copying to your project. There are plenty of open source libraries now available with C…
This video discusses moving either the default database or any database to a new volume.
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.

760 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now