iOS:如何获取所有者的电子邮件地址?

编程入门 行业动态 更新时间:2024-10-19 08:44:29
本文介绍了iOS:如何获取所有者的电子邮件地址?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

在iOS中,如何阅读存储在iPhone中的所有者电子邮件地址?在我的应用中,我想让用户选择他想要与自定义服务关联的电子邮件地址。在Android上,我会让他选择他的GMail地址,但在iOS上,似乎没有选择获取apple id电子邮件,对吧?那么是否有可能检索所有存储的电子邮件地址并让用户选择其中一个?我真的需要一个电子邮件地址。一个唯一的ID,设备ID或类似内容将无法满足我的目标。

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.

谢谢

推荐答案

为什么不出示通讯录并让用户选择和发送电子邮件地址?

Why not present the address book and let the user choose and email address?

将AddressBook和AddressBookUI框架添加到您的项目。 在.h中导入它们并添加协议ABPeoplePickerNavigationControllerDelegate。

Add the AddressBook and AddressBookUI frameworks to your project. Import them in your .h and add the protocol ABPeoplePickerNavigationControllerDelegate.

然后调用地址簿:

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

让用户输入联系方式:

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

更多推荐

iOS:如何获取所有者的电子邮件地址?

本文发布于:2023-06-08 21:29:41,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/589384.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:所有者   电子邮件地址   iOS

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!