在iOS中,如何读取存储在iPhone中的所有者电子邮件地址?在我的应用程序中,我想让用户选择他要与自定义服务关联的电子邮件地址.在
Android上,我可以让他选择他的GMail地址,但在iOS上,似乎没有选择获取apple id的电子邮件,对吧?那么有可能检索所有存储的电子邮件地址,并让用户选择其中的一个?我真的需要一个电子邮件地址.唯一的ID,设备ID或类似功能将无法与我想要实现的功能一起使用.
谢谢
解决方法
为什么不出示通讯录,让用户选择和电子邮件地址?
将AddressBook和AddressBookUI框架添加到您的项目中.
将它们导入到.h中并添加协议ABPeoplePickerNavigationControllerDelegate.
然后打电话给地址簿:
- (void) chooseContact:(id)sender { ABPeoplePickerNavigationController *picker = [[ABPeoplePickerNavigationController alloc] init]; picker.peoplePickerDelegate = self; [self presentModalViewController:picker animated:YES]; [picker release]; }
// call when the user cancel - (void) peoplePickerNavigationControllerDidCancel:(ABPeoplePickerNavigationController *)peoplePicker { [self dismissModalViewControllerAnimated:YES]; }
让用户输入联系方式:
- (BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person { return YES; }
然后使用所选的电子邮件地址做你所想要的:
- (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; }