Reputation: 1067
In iOS, how can I read the owners email adresses that are stored in the iPhone? In my app, I'd like to let the user choose which email address he would like to associate with a custom service. On Android, I would let him choose his GMail address, but on iOS, there seems to be no option to get the apple id email, right? So is there any possibility to retrieve all stored email addresses and let the user choose one of them? I really need an email address. A unique id, device id or similar won't work with what I'd like to achieve.
Thanks
Upvotes: 16
Views: 14466
Reputation: 69469
As per Apple guidelines, you would have to ask the user. Also apple isn't very keen on making private information, like email, mandatory.
You could loop through the address book and look for the owner tag in the contact, but note that Apple will notify the user in upcoming iOS release that an app is accessing the address book, so a user might not allow your app the access the address book.
Upvotes: 1
Reputation: 742
Why not present the address book and let the user choose and email address?
Add the AddressBook and AddressBookUI frameworks to your project. Import them in your .h and add the protocol ABPeoplePickerNavigationControllerDelegate.
Then call the adress book:
- (void) chooseContact:(id)sender {
ABPeoplePickerNavigationController *picker = [[ABPeoplePickerNavigationController alloc] init];
picker.peoplePickerDelegate = self;
[self presentModalViewController:picker animated:YES];
[picker release];
}
You implement several required delegate methods to get an email address and dismiss the Address Book:
// call when the user cancel
- (void) peoplePickerNavigationControllerDidCancel:(ABPeoplePickerNavigationController *)peoplePicker {
[self dismissModalViewControllerAnimated:YES];
}
Let the user enter in contact details:
- (BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person {
return YES;
}
Then do what you you with the email address selected:
- (BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person property:(ABPropertyID)property identifier:(ABMultiValueIdentifier)identifier {
if (property == kABPersonEmailProperty) {
//assumed you have a property email in your class
self.email = (NSString *)ABRecordCopyValue(person, kABPersonEmailProperty);
[self dismissModalViewControllerAnimated:YES];
}
return NO;
}
Upvotes: 10
Reputation: 7840
nope you cannot get list of emails, the default mail app which we use to send the emails through our app only let you check if user can send email or not which is its check wether or not atelast one mail account has been configured or not
Upvotes: 1