Problem with vCard and AddressBook ABPerson UID, HELP!!

  • Hi all

    I've been fighting now with the AdressBook API for a while and found a disturbing problem. Maybe someone can help.

    I'm trying to use the AddressBook as my main person "database" in my application. I've create a small function that accepts drag - drops from the Address book to add a new person in my app. So far so good.

    I'm trying after to show in my application details about that linked person and that's where everything falls down.

    On drop, I read the vCard created by the AddressBook using this line:

    ABPerson* aPerson = [[ABPerson alloc] initWithVCardRepresentation:filedata];

    When doing this, the UID of my person gets re-generated. I wanted to use the UID as my reference to my original address book record and dig the information using it. But since its re-generated upon read of the vCard, no luck. So the call:
    ABAddressBook* addressBook = [ABAddressBook addressBook];
    ABRecord* abRecord = [addressBook recordForUniqueId:personId];

    always return null.
    But, if I use the sharedAddressBook instead, my UIDs still get re-generated but this guy (the sharedAddressBook) can find the records but only in the same execution of the application. Upon restart, same old no-match problem.

    There must be something i REALLY don't understand about the AB but can't find anything more, out of ideas.

    Anybody knows what's going on? Any way we can prevent my vCard initialization from re-genrating the UID? If not, then what would be the correct way to refer to AB records from another application? Running a search based on names sounds bad compared to using direct pointers to records, the UID.

    Thank you !
    Eric.
  • > 've been fighting now with the AdressBook API for a while and found a disturbing problem. Maybe someone can help.
    >
    > I'm trying to use the AddressBook as my main person "database" in my application. I've create a small function that accepts drag - drops from the Address book to add a new person in my app. So far so good.
    >
    > I'm trying after to show in my application details about that linked person and that's where everything falls down.
    >
    > On drop, I read the vCard created by the AddressBook using this line:
    >
    > ABPerson* aPerson = [[ABPerson alloc] initWithVCardRepresentation:filedata];

    That always creates a brand new contact with a brand new uniqueID.  As you observe.  I'm pretty sure it's not an appropriate way to pass around a *reference* to an existing contact.  That's what -[ABRecord uniqueId] is for.  You should get the uniqueId, pass that around, and then use -[ABAddressBook recordForUniqueId:] to look up the contact.

    - Ben

    >
    > When doing this, the UID of my person gets re-generated. I wanted to use the UID as my reference to my original address book record and dig the information using it. But since its re-generated upon read of the vCard, no luck. So the call:
    > ABAddressBook* addressBook = [ABAddressBook addressBook];
    > ABRecord* abRecord = [addressBook recordForUniqueId:personId];
    >
    > always return null.
    > But, if I use the sharedAddressBook instead, my UIDs still get re-generated but this guy (the sharedAddressBook) can find the records but only in the same execution of the application. Upon restart, same old no-match problem.
    >
    > There must be something i REALLY don't understand about the AB but can't find anything more, out of ideas.
    >
    > Anybody knows what's going on? Any way we can prevent my vCard initialization from re-genrating the UID? If not, then what would be the correct way to refer to AB records from another application? Running a search based on names sounds bad compared to using direct pointers to records, the UID.
  • >> I'm trying to use the AddressBook as my main person "database" in my application. I've create a small function that accepts drag - drops from the Address book to add a new person in my app. So far so good.
    >>
    >> I'm trying after to show in my application details about that linked person and that's where everything falls down.
    >>
    >> On drop, I read the vCard created by the AddressBook using this line:
    >>
    >> ABPerson* aPerson = [[ABPerson alloc] initWithVCardRepresentation:filedata];

    It’s been a long time since I did this, but IIRC you don’t want to use the vCard data on the pasteboard. There’s another data flavor put there by AB that contains the cards UID, I think. Try getting the PasteboardPeeker app [it’s Apple sample code] and dragging from AB.app into it, to see what all the data types are.

    —Jens
  • Hi guys

    Thank you so much!!

    I knew I was missing an important part here. I'll pay more attention next time to the content of the Pasteboard types. The answers were all there.
    That also directed my to the proper way to actually handling the data content of the pboard, using the plist + NSPropertyListSerialization class. I was previously using a regex :).

    All is so clean now. That even solved the problem I had with the PeoplePicker. This guy says it carries vcard but there is a bug with this feature in the control. I fails also trying to drag - drop people on the desktop, where the AddressBook succeeds. But using this content type: ABPeopleUIDsPboardType everything works like a charm!

    Thank you again both.

    Eric.

    On 2010-04-08, at 12:35 AM, Ben Trumbull wrote:

    >> 've been fighting now with the AdressBook API for a while and found a disturbing problem. Maybe someone can help.
    >>
    >> I'm trying to use the AddressBook as my main person "database" in my application. I've create a small function that accepts drag - drops from the Address book to add a new person in my app. So far so good.
    >>
    >> I'm trying after to show in my application details about that linked person and that's where everything falls down.
    >>
    >> On drop, I read the vCard created by the AddressBook using this line:
    >>
    >> ABPerson* aPerson = [[ABPerson alloc] initWithVCardRepresentation:filedata];
    >
    > That always creates a brand new contact with a brand new uniqueID.  As you observe.  I'm pretty sure it's not an appropriate way to pass around a *reference* to an existing contact.  That's what -[ABRecord uniqueId] is for.  You should get the uniqueId, pass that around, and then use -[ABAddressBook recordForUniqueId:] to look up the contact.
    >
    > - Ben
    >
    >>
    >> When doing this, the UID of my person gets re-generated. I wanted to use the UID as my reference to my original address book record and dig the information using it. But since its re-generated upon read of the vCard, no luck. So the call:
    >> ABAddressBook* addressBook = [ABAddressBook addressBook];
    >> ABRecord* abRecord = [addressBook recordForUniqueId:personId];
    >>
    >> always return null.
    >> But, if I use the sharedAddressBook instead, my UIDs still get re-generated but this guy (the sharedAddressBook) can find the records but only in the same execution of the application. Upon restart, same old no-match problem.
    >>
    >> There must be something i REALLY don't understand about the AB but can't find anything more, out of ideas.
    >>
    >> Anybody knows what's going on? Any way we can prevent my vCard initialization from re-genrating the UID? If not, then what would be the correct way to refer to AB records from another application? Running a search based on names sounds bad compared to using direct pointers to records, the UID.
    >

    Eric Giguere
    <eric.giguere...>
previous month april 2010 next month
MTWTFSS
      1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30    
Go to today