Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
478 views
in Technique[技术] by (71.8m points)

iphone - iOS: How to get owners email address?

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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;
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...