views:

829

answers:

3

So I'm stumped on this one.

In Mac OS X there is an easy way to get the "Me" card (the owner of the Mac/account) from the built-in address book API.

Has anyone found a way to find out which contact (if it exists) belongs to the owner of the iPhone?

+3  A: 

There is no such API in the iPhone SDK 2.2.1 and earlier. Please file a request for it at: http://bugreport.apple.com

Mike Abdullah
Is this still true in the 3.1 SDK?
Steven Fisher
Yes, I believe so
Mike Abdullah
+2  A: 

You could use the undocumented user default:

[[NSUserDefaults standardUserDefaults] objectForKey:@"SBFormattedPhoneNumber"];

and then search the address book for the card with that phone number.

Keep in mind that since the User Default is undocumented, Apple could change at any time and you may have trouble getting into the App Store.

Another approach you could take, although it is much more fragile, is to look at the device name. If the user hasn't changed it from the default "User Name's iPhone" AND they are using their real name as an iPhone, you could grab the user name from that. Again, not the best solution by any means, but it does give you something else to try.

The generally accepted answer to this question is to file a Radar with Apple for this feature and to prompt users to choose their card.

Martin Gordon
Apps have been rejected from the store for doing this. Anyway it's not reliable-- if the user ported their phone number from another cell phone carrier, this call almost certainly gives an incorrect result.
Tom Harrington
Thanks for the help. After posting this questions, I though about the SBFormattedPhoneNumber approach. It could easily be implemented in a a "safe" future proof way, but it sounds like Apple may be discouraging this for a variety of reasons. Also, Tom, thanks for the heads up.
Kailoa Kadano
+1  A: 

There's no API for getting the "me" card because there is no "me" card. The iPhone's contacts app has no way of marking a card as being "me", and the API reflects this.

Tom Harrington