如何在iPhone中获取已配置的电子邮件

如何在iPhone中获取已配置的电子邮件,iphone,cocoa-touch,Iphone,Cocoa Touch,我需要使用cocoa touch获取iPhone中配置的用户电子邮件。我该怎么做呢 感谢您的回答。此代码将获取通讯簿中的所有联系人,并输出与他们相关的电子邮件地址: // get a list of all contacts in the address book db ABAddressBookRef ab = ABAddressBookCreate(); CFArrayRef contacts = ABAddressBookCopyArrayOfAllPeople(ab); CFIndex

我需要使用cocoa touch获取iPhone中配置的用户电子邮件。我该怎么做呢


感谢您的回答。

此代码将获取通讯簿中的所有联系人,并输出与他们相关的电子邮件地址:

// get a list of all contacts in the address book db
ABAddressBookRef ab = ABAddressBookCreate();
CFArrayRef contacts = ABAddressBookCopyArrayOfAllPeople(ab);
CFIndex nPeople = ABAddressBookGetPersonCount(ab);

for( int i = 0; i < nPeople; ++i ) {
    ABRecordRef ref = CFArrayGetValueAtIndex(contacts,i);

    // output the contact's name
    CFStringRef firstName = ABRecordCopyValue(ref, kABPersonFirstNameProperty);
    CFStringRef lastName = ABRecordCopyValue(ref, kABPersonLastNameProperty);
    NSString *contactFirstLast = [NSString stringWithFormat:@"%@,%@:",
                                    firstName, lastName];
    NSLog(@"%@", contactFirstLast);

    // output all email addresses stored for the contact
    ABMultiValueRef emailRef = ABRecordCopyValue(ref, kABPersonEmailProperty);
    CFIndex nEmails = ABMultiValueGetCount(emailRef);
    CFArrayRef emails = ABMultiValueCopyArrayOfAllValues(emailRef);
    for( int j = 0; j < nEmails; ++j ) {
        CFStringRef email = CFArrayGetValueAtIndex(emails, j);
        NSLog(@"\t%@", email);
    };

    // clean up
    CFRelease(emailRef);
    CFRelease(firstName);
    CFRelease(lastName);
}

CFRelease(contacts);
//获取通讯簿数据库中所有联系人的列表
ABAddressBookRef ab=ABAddressBookCreate();
CFArrayRef contacts=ABAddressBookCopyArrayFallPeople(ab);
CFIndex nPeople=ABAddressBookGetPersonCount(ab);
for(int i=0;i
什么是“用户电子邮件”?您是指用户存储在通讯簿中的地址吗?用户自己的电子邮件地址?什么?