Getting user's default email address in Cocoa

后端 未结 2 1384
不思量自难忘°
不思量自难忘° 2020-12-02 21:51

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.

相关标签:
2条回答
  • 2020-12-02 22:13

    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];
    
    0 讨论(0)
  • 2020-12-02 22:28

    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.

    0 讨论(0)
提交回复
热议问题