I am trying to get email id and other details from iPhone/iPad setting area to my code using objective c. Any suggestion would appreciated. Thanks in advance.
Asked
Active
Viewed 1,535 times
3 Answers
0
As far as I understand your question you want to get personal data from the user. For this you need to call the AdressBook API:

suzhi
- 161
- 2
- 11
-
No,I am trying to get values from configured email account in device. Say for example if i configure a gmail account in my device so i want that mail id and other details in my project. – Deepak Arora Jan 23 '13 at 09:55
0
Here is working example. It loads all emails and full names to passed array. Tailor this code in a way you need, for example, you could find some specific contact and get all info from it.
- (NSMutableArray *)loadContactsFromAB:(NSMutableArray *)contacts
{
ABAddressBookRef addressBook = ABAddressBookCreate();
CFArrayRef allPeople = ABAddressBookCopyArrayOfAllPeople(addressBook);
CFIndex nPeople = ABAddressBookGetPersonCount(addressBook);
for (int i = 0 ; i < nPeople ; i++ ) {
ABRecordRef person = CFArrayGetValueAtIndex(allPeople, i);
NSString *firstName = ABRecordCopyValue(person, kABPersonFirstNameProperty);
NSString *lastName = ABRecordCopyValue(person, kABPersonLastNameProperty);
NSString *fullName;
if (firstName && lastName) {
fullName = [NSString stringWithFormat:@"%@ %@", firstName, lastName];
} else {
if (firstName) {
fullName = [NSString stringWithString:firstName];
} else if (lastName) {
fullName = [NSString stringWithString:lastName];
} else {
continue;
}
}
NSString *email = nil;
ABMultiValueRef emails = ABRecordCopyValue(person, kABPersonEmailProperty);
if (emails) {
NSArray *emailAddresses = [(NSArray *)ABMultiValueCopyArrayOfAllValues(emails) autorelease];
if (emailAddresses && [emailAddresses count] > 0)
email = [emailAddresses objectAtIndex:0];
CFRelease(emails);
}
if (email) {
NSDictionary *contact = [NSDictionary
dictionaryWithObjectsAndKeys:fullName, @"name",
email, @"email", nil];
[self addContact:contacts contact:contact];
}
if (firstName)
CFRelease(firstName);
if (lastName)
CFRelease(lastName);
}
CFRelease(allPeople);
CFRelease(addressBook);
return contacts;
}

Cynichniy Bandera
- 5,991
- 2
- 29
- 33
-
Thanks for prompt answer, But I want to get the details of configured email account in device. Say for example i configure a gmail account in my device, so i want to get mail address and other details in the Xcode. – Deepak Arora Jan 23 '13 at 09:57
0
you cannot get the default email in settings, it will handle only by mfmailcomposeviewcontroller

anu
- 1