Created
August 1, 2009 17:48
-
-
Save roustem/159755 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <AddressBook/AddressBook.h> | |
static NSString* defaultEmail() | |
{ | |
NSString* result = @""; | |
@try { | |
ABPerson *me = [[ABAddressBook sharedAddressBook] me]; | |
if (me == nil) return result; | |
ABMultiValue *emails = [me valueForProperty:kABEmailProperty]; | |
if (emails == nil) return result; | |
NSString* primaryEmailId = [emails primaryIdentifier]; | |
NSUInteger primaryEmailIndex = NSNotFound; | |
if (primaryEmailId) primaryEmailIndex = [emails indexForIdentifier:primaryEmailId]; | |
if (primaryEmailIndex != NSNotFound) result = [emails valueAtIndex:primaryEmailIndex]; | |
} | |
@catch (NSException* e) { | |
NSLog(@"Failed to obtain the e-mail address: %@", e); | |
} | |
return result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment