12

How do I obtain the user's default email address? I need to obtain it for my crash reporter dialog, so the user won't have to fill it out manually.

kevboh
  • 5,207
  • 5
  • 38
  • 54
Enchilada
  • 3,859
  • 1
  • 36
  • 69

2 Answers2

17

Never mind, I got it. First, I just have to add AddressBook.framework into my Linked Frameworks. Then, this is the code required:

#import <AddressBook/AddressBook.h>

NSString *theEmailAddressWeWantToObtain = @"";
ABPerson *aPerson = [[ABAddressBook sharedAddressBook] me];
ABMultiValue *emails = [aPerson valueForProperty:kABEmailProperty];
if([emails count] > 0)
  theEmailAddressWeWantToObtain = [emails valueAtIndex:0];
Enchilada
  • 3,859
  • 1
  • 36
  • 69
1

From "*Address Book Programming Guide for iOS":

Link the Address Book UI and Address Book frameworks to your project.

Important The project will fail to build (with a linker error) if you do not link against both of these framework.

Linking in the Framework without the UI will prevent the sample code from compiling.

EliSKoren
  • 81
  • 1
  • 3
  • The above poster is suggesting that in any project using the Address Book Framework, you should also include Address Book UI. – binary_falcon Dec 06 '13 at 02:27