Get the ABRecordID from newly added Address Book Object ios
Asked Answered
L

1

8

I have an application that adds Contacts to the Address Book in iOS, and all I need is to store the ABRecordID or ABRecordref as soon as I save the contact.

ABAddressBookAddRecord(addressbook, newPerson, &theerror);
ABAddressBookSave(addressbook, &theerror);

This question is extremely similar, but I don't understand the answer: ABRecordID for a record in addressbook(unique id for inserted record in addressbook)

How do you know the

ABRecordID ABRecordGetRecordID (
ABRecordRef newPerson
);

Some help here would be fantastic - thanks!

Liddy answered 27/7, 2013 at 22:45 Comment(0)
Y
19

Simply call ABRecordGetRecordID(newPerson) after you've saved the address book (before that, there won't be a valid ID).

//...
ABRecordID recordID = ABRecordGetRecordID(newPerson);

An ABRecordID is the same as an int_32 (a 32-bit integer).

Yuille answered 27/7, 2013 at 22:55 Comment(9)
That's the ticket! Thanks omz you da man. Gonna accept your answer in 2 minutes when I'm allowed.Liddy
Its always giving -1 as ABRecordID with native contact picker ABRecordRef in ios 8.1Schwenk
@Schwenk this is a complete guess but maybe since you don't get contact permission from the user when using the ios 8 native contact picker apple is hiding the record id by always returning it as -1?Lukewarm
@Lukewarm Yes you are right, iOS 8 create copy of contact picked, so person reference is not available in db and hence ABRecordGetRecordID provide -1Schwenk
@Schwenk Hi. I am stuck in getting ABRecordGetRecordID in swift. I am always getting 1. Can you please help me. I need it very badly.Brynnbrynna
@EktaPadaliya With current iOS, you can always use CNContact and it will provide you identifier as well which is unique among contacts on the device.Schwenk
@Schwenk So identifier and ABRecordGetRecordID is same right?Brynnbrynna
@EktaPadaliya First- ABRecordGetRecordID is available iOS2.0- iOS9.0, ABAddressBook (ABRecordGetRecordID) - The unique ID of record when the record exists in the Address Book database., CNContact (identifier) - The identifier is unique among contacts on the device. It can be saved and used for fetching contacts next application launch. Copied from developer.apple :)Schwenk
@EktaPadaliya yes this looks similar to RecordIdSchwenk

© 2022 - 2024 — McMap. All rights reserved.