Thursday, April 08, 2010

ABGetMe with the iPhone SDK

Unlike the Mac Address Book API, the iPhone Address Book API does not come with the ABGetMe function. That's a pity, but we can do something about it.

Recently, I used MFMailComposeViewController for the first time and I realized that it was displaying my e-mail address. Nicolas Seriot already demonstrated how to retrieve all your e-mail account information in SpyPhone, but I felt there was a more lightweight method for retrieving the e-mail addresses by taking advantage of the MessageUI framework. A class-dump and five minutes later, here is my solution:

5 comments:

lksinc said...

Cédric,

I can't seem to use this. Is it limited to a certain version of the iOS by any chance?

lksinc said...

Duh, should have done a little trying before posting. In fact, the class name has changed to MFMailComposeController (not sure if it happened in 3.2 or 4.0 though)

Cédric Luthi said...

No, that's MailComposeController, it's an internal class of MFMailComposeController. You must link with the MessageUI framework for this code to work.

Cédric Luthi said...

My bad, the +accountEmailAddresses method has indeed changed in iOS 3.2 or 4.0 and is now on the MFMailComposeController class. The code is updated to acknowledge that change.

jay paul said...

Great post your given information does help me a lot knowing that you have shared this information here freely.

Samsung - 11.6" Geek Squad Certified Refurbished Chromebook - 2GB Memory - 16GB Flash (eMMc) Memory

Samsung - 15.6" Geek Squad Certified Refurbished Laptop - 8GB Memory - 1TB Hard Drive