I want to get the user mail address, as shown in this thread : Getting user's default email address in Cocoa
But when I tried :
NSString *theEmailAddressWeWantToObtain = @"";
ABPerson *aPerson = [[ABAddressBook sharedAddressBook] me];
ABMultiValue *emails = [aPerson valueForProperty:kABEmailProperty];
if([emails count] > 0)
theEmailAddressWeWantToObtain = [emails valueAtIndex:0];
I have these errors :
- Use of undeclared identifier ‘aPerson’
- Use of undeclared identifier ‘ABAddressBook’
- Unknown type ‘ABMultiValue’
I’ve linked AddressBook and AddressBookUI, and imported AddressBook/AddressBook.h
What’s wrong ?
These are the corrections to your code
I’m not so familiar with Key Value Coding, so I’m not sure about your methods related to that.
This is the way I would do it
There are three email address stored in the email
ABMultiValueRef: home, work, and other emails. Try this code to get the home email:If you have any questions about the code, just ask in the comments. Hope this helps!
EDIT:
The
PSAddressBookclass mentioned in the code can be found here: https://github.com/pasawaya/PSAddressBook