iOS:如何获取所有者的电子邮件地址? [英] iOS: How to get owners email address?

查看:135
本文介绍了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:如何获取所有者的电子邮件地址?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆