• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
[SOLVED] Re: AddressBook Country Code + ABAddressBook Drag Hack
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[SOLVED] Re: AddressBook Country Code + ABAddressBook Drag Hack


  • Subject: [SOLVED] Re: AddressBook Country Code + ABAddressBook Drag Hack
  • From: Philip Dow <email@hidden>
  • Date: Sun, 28 May 2006 01:58:56 +0200

Boy, you know, I searched Google for an answer to this question without finding one but finally came across it in the docs:

ABAddressBook provides - (NSAttributedString *) formattedAddressFromDictionary:(NSDictionary *)address . All I need to do is pass it the dictionary and a well formed address is returned.

In the meantime, I also came across a neat way to handle drags from the shared ABAddressBook. Problems have been reported in the past here because the vCard data put on the pasteboard does not yield records identical to those being dragged.

Well, the drag source is an instance of ABTableView, so if you check for that then work you way up the superview chain, eventually you reach the ABPeoplePickerView which you can query for the selected records, the very same ones being dragged!.

Stick this in your performDragOperation: method, make sure you place @class ABTableView somewhere in your header though.

if ( [[sender draggingSource] isKindOfClass:[ABTableView class]] ) {
	//
	// the drag is originating from the ABPeoplePickerView

	NSView *aView = source;
	while ( aView = [aView superview] ) {
		if ( [aView isKindOfClass:[ABPeoplePickerView class]] ) break;
	}

	if ( aView == nil ) return NO;
	else {
		int i;
		NSArray *records = [(ABPeoplePickerView*)aView selectedRecords];
		for ( i = 0; i < [records count]; i++ )
			[self addPersonToText:[records objectAtIndex:i]];
		}
}

Works like a charm!
-Phil


On May 27, 2006, at 4:32 PM, Philip Dow wrote:

I'm using the AddressBook framework to look up information on records by unique id. Once I have the record I can successfully pull all kinds of information from it using the framework.

One piece of information I'm dealing with is address information. The framework stores this data in a dictionary accessible by a limited number of keys, ie City, Country, Street, Zip and State. Additionally, the dictionary includes a CountryCode key with values of "us" for United States, "at" for Austria and so on.

Address Book will correctly order and display the rest of the keys in the dictionary based on the country code. Is it possible to derive an address format from this country code programmatically using the AddressBook framework or any other cocoa framework, so as to also properly format and display a particular address?

The AddressBook framework provides a single function, ABLocalizedPropertyOrLabel(), but that will not convert a country code such as "us" to the appropriate address format. Any thoughts?

-Phil
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


_______________________________________________ Do not post admin requests to the list. They will be ignored. Cocoa-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
References: 
 >AddressBook Country Code -> Address Format (From: Philip Dow <email@hidden>)

  • Prev by Date: Re: Text Editor mini-toolbar like BBEdit or Xcode
  • Next by Date: Multiple NSToolbars (like iPhoto)
  • Previous by thread: AddressBook Country Code -> Address Format
  • Next by thread: Image cache: Where is it and how do I refresh it?
  • Index(es):
    • Date
    • Thread