ABPeoplePickerView drag & drop

  • Hi all,

    My application uses an ABPeoplePickerView to access the local address
    book. I want to drag and drop entries onto the app's main window in
    order to create instances which refer to the appropriate ABPerson or
    ABGroup.

    Is there a sample code out there that demonstrates the drag & drop part
    (i.e., how the selected person's/group's IDs are taken to another view)?

    I searched for it, but did not find anything appropriate. Apple's
    Address Book Programming Guide briefly mentioned the people picker, but
    does not discuss dragging & dropping of people/groups.

    Thanks for any hint.
    /CA
  • On Sep 18, 2007, at 6:10 AM, Claus Atzenbeck wrote:

    > My application uses an ABPeoplePickerView to access the local address
    > book. I want to drag and drop entries onto the app's main window in
    > order to create instances which refer to the appropriate ABPerson or
    > ABGroup.
    >
    > Is there a sample code out there that demonstrates the drag & drop
    > part
    > (i.e., how the selected person's/group's IDs are taken to another
    > view)?

    Hey Claus,

    If there is nothing documented as far as what pasteboard types are
    actually available from a dragging pasteboard, you can often gain
    some insight by using the PasteboardPeeker sample code, provided by
    Apple at <http://developer.apple.com/samplecode/PasteboardPeeker/
    index.html
    >.

    ABPeoplePickerView seems to place a variety of data formats onto the
    dragging pasteboard.  Single person drags seem to exist in at least
    two useful formats, specifically "Apple VCard pasteboard type" and
    "ABPeopleUIDsPboardType."  A likely useful representation of groups
    exist as "ABGroupsUIDsPboardType."

    I could not find these pasteboard type strings declared in any of the
    ABAddressBook framework's headers, but you can represent them in your
    code as a simple NSString constants.

    Here are some quick examples of creating address book entities using
    each pasteboard format:

    NSData *vCardData = [draggingPasteboard dataForType:@"Apple VCard
    pasteboard type"];
    ABPerson *person = [[ABPerson alloc]
    initWithVCardRepresentation:vCardData];

    Or, a more generic approach:

    NSString *recordId = [[draggingPasteboard
    propertyListForType:@"ABGroupsUIDsPboardType"] objectAtIndex:0];
    ABRecord *record = [[ABAddressBook sharedAddressBook]
    recordForUniqueId:recordId];
    (same for "ABPeopleUIDsPboardType")

    Admittedly, I never really had a need to deal with the address book
    API, so there could perhaps exist a better technique for accessing
    the record information.  In general, though, examining
    PasteboardPeeker's output should provide enough clues as to what data
    is available and how you can extract it from ABPeoplePickerView's
    dragging session.

    Also, there could be some fragility to this approach as well, since
    we're manually declaring the types ourselves, and, if the behavior is
    in fact undocumented, Apple could technically reserve the right to
    change the implementation of ABPeoplePickerView's dragging source
    operations.

    Hopefully this at least gives you something to work with.

    Take care,
    -Sean
  • On Tue, 18 Sep 2007, Sean Murphy wrote:

    > If there is nothing documented as far as what pasteboard types are actually
    > available from a dragging pasteboard, you can often gain some insight by using
    > the PasteboardPeeker sample code, provided by Apple at
    > <http://developer.apple.com/samplecode/PasteboardPeeker/index.html>.

    Hello Sean, this and the rest of your detailed e-mail helped a lot.
    Thanks for those hints!

    Cheers,
    Claus
previous month september 2007 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