我正在尝试使用目标 c 从 iPhone/iPad 设置区域获取电子邮件 ID 和其他详细信息到我的代码。任何建议将不胜感激。提前致谢。
问问题
1523 次
3 回答
0
您无法在设置中获取默认电子邮件,它将仅由 mfmailcomposeviewcontroller 处理
于 2013-07-18T10:59:12.957 回答
0
据我了解您的问题,您希望从用户那里获取个人数据。为此,您需要调用 AdressBook API:
于 2013-01-23T07:59:29.190 回答
0
这是工作示例。它将所有电子邮件和全名加载到传递的数组中。以您需要的方式定制此代码,例如,您可以找到一些特定的联系人并从中获取所有信息。
- (NSMutableArray *)loadContactsFromAB:(NSMutableArray *)contacts
{
ABAddressBookRef addressBook = ABAddressBookCreate();
CFArrayRef allPeople = ABAddressBookCopyArrayOfAllPeople(addressBook);
CFIndex nPeople = ABAddressBookGetPersonCount(addressBook);
for (int i = 0 ; i < nPeople ; i++ ) {
ABRecordRef person = CFArrayGetValueAtIndex(allPeople, i);
NSString *firstName = ABRecordCopyValue(person, kABPersonFirstNameProperty);
NSString *lastName = ABRecordCopyValue(person, kABPersonLastNameProperty);
NSString *fullName;
if (firstName && lastName) {
fullName = [NSString stringWithFormat:@"%@ %@", firstName, lastName];
} else {
if (firstName) {
fullName = [NSString stringWithString:firstName];
} else if (lastName) {
fullName = [NSString stringWithString:lastName];
} else {
continue;
}
}
NSString *email = nil;
ABMultiValueRef emails = ABRecordCopyValue(person, kABPersonEmailProperty);
if (emails) {
NSArray *emailAddresses = [(NSArray *)ABMultiValueCopyArrayOfAllValues(emails) autorelease];
if (emailAddresses && [emailAddresses count] > 0)
email = [emailAddresses objectAtIndex:0];
CFRelease(emails);
}
if (email) {
NSDictionary *contact = [NSDictionary
dictionaryWithObjectsAndKeys:fullName, @"name",
email, @"email", nil];
[self addContact:contacts contact:contact];
}
if (firstName)
CFRelease(firstName);
if (lastName)
CFRelease(lastName);
}
CFRelease(allPeople);
CFRelease(addressBook);
return contacts;
}
于 2013-01-23T08:26:43.373 回答