Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting user's default email address in Cocoa

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.

like image 813
Enchilada Avatar asked Feb 03 '11 23:02

Enchilada


1 Answers

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];
like image 109
Enchilada Avatar answered Sep 21 '22 21:09

Enchilada