Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8146741
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T14:06:19+00:00 2026-06-06T14:06:19+00:00

I want to get the user mail address, as shown in this thread :

  • 0

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 ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T14:06:20+00:00Added an answer on June 6, 2026 at 2:06 pm

    These are the corrections to your code

    NSString *theEmailAddressWeWantToObtain = @"";
    ABPerson *aPerson = [[ABAddressBook sharedAddressBook] me];
    ABMultiValueRef *emails = [aPerson valueForProperty:kABEmailProperty]; //No such thing as ABMultiValue; it's ABMultiValueRef
    if(ABMultiValueGetCount(emails) > 0) //"emails" is not an array, so you can't use the "count" method
        theEmailAddressWeWantToObtain = [emails valueAtIndex:0];
    

    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:

    NSString *email;
    
    ABRecordRef currentPerson = (__bridge ABRecordRef)[[PSAddressBook arrayOfContacts] objectAtIndex:identifier];
    ABMultiValueRef emailsMultiValueRef = ABRecordCopyValue(currentPerson, kABPersonEmailProperty);
    
    NSUInteger emailsCount;    
    //Goes through the emails to check which one is the home email
    for(emailsCount = 0; emailsCount <= ABMultiValueGetCount(emailsMultiValueRef);emailsCount++){ 
        NSString *emailLabel = (__bridge_transfer NSString *)ABMultiValueCopyLabelAtIndex (emailsMultiValueRef, emailsCount);
    
        if([emailLabel isEqualToString:@"Home"]){
    
            if ((__bridge_transfer NSString *)ABMultiValueCopyValueAtIndex(emailsMultiValueRef, emailsCount) != NULL){
    
                email = (__bridge_transfer NSString *)ABRecordCopyValue(currentPerson, kABPersonEmailProperty);
            }   
    
            //If the last name property does not exist
            else{
    
                email = @"NULL";
            }
        }
    }
    
    CFRelease(emailsMultiValueRef);
    

    If you have any questions about the code, just ask in the comments. Hope this helps!

    EDIT:

    The PSAddressBook class mentioned in the code can be found here: https://github.com/pasawaya/PSAddressBook

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

If I want to get a user that has the email address of 'me@example.com',
i want to get the user who login now .. how to do this
i want to get the full address of user programatically using c# how can
I just want to get email id of user having phone number given. so
I want to get the user ID of a given process ID using C
I want to get the home directory of a user of a unix system.
i want to get all the details of youtube,so if the user tick the
I'm trying to get the user to confirm if they want to delete a
I want to insert an user and get its id e.g. last insert id.
I want to make call to authenticate user and get back token in json

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.