关于从 iPhone 通讯录中检索所有电子邮件 ID 的问题
我是地址簿编程的新手。我想从地址簿中检索所有电子邮件 ID。问题是下面的代码获取一条记录(一个人)的所有数据。但是当我在地址簿中添加多个联系人时。它压碎了,没有表现出任何异常。
有什么建议吗?提前致谢。
self.pastUrls = [[NSMutableArray alloc] init];
ABAddressBookRef addressBook = ABAddressBookCreate();
NSArray *addresses = (NSArray *) ABAddressBookCopyArrayOfAllPeople(addressBook);
// you could probably do some kind of enumeration but I'm doing old fashoined way
int i;
for(i = 0; i < [addresses count]; i++) {
ABRecordRef record = [addresses objectAtIndex:i];
ABMultiValueRef multiValue = ABRecordCopyValue(record, kABPersonEmailProperty);
NSLog(@"%@",multiValue);
int count = ABMultiValueGetCount(multiValue);
NSLog(@"%d",count);
int j;
for(j = 0; j < count; j++) {
NSString *label = (NSString *)ABAddressBookCopyLocalizedLabel(ABMultiValueCopyLabelAtIndex(multiValue, i));
NSString *value = (NSString *)ABMultiValueCopyValueAtIndex(multiValue, i);
//NSLog(@"Email for %@: %@", label, value);
[pastUrls addObject:value];
}
}
问候, 萨蒂什
I am newbie to Address book programming. I want to retrieve all email id's from address book.The issue is below code gets the all data for one record(one person). but When i add more than one contact in address book. it crushes without showing any exception.
Any suggestions? Thanks in advance.
self.pastUrls = [[NSMutableArray alloc] init];
ABAddressBookRef addressBook = ABAddressBookCreate();
NSArray *addresses = (NSArray *) ABAddressBookCopyArrayOfAllPeople(addressBook);
// you could probably do some kind of enumeration but I'm doing old fashoined way
int i;
for(i = 0; i < [addresses count]; i++) {
ABRecordRef record = [addresses objectAtIndex:i];
ABMultiValueRef multiValue = ABRecordCopyValue(record, kABPersonEmailProperty);
NSLog(@"%@",multiValue);
int count = ABMultiValueGetCount(multiValue);
NSLog(@"%d",count);
int j;
for(j = 0; j < count; j++) {
NSString *label = (NSString *)ABAddressBookCopyLocalizedLabel(ABMultiValueCopyLabelAtIndex(multiValue, i));
NSString *value = (NSString *)ABMultiValueCopyValueAtIndex(multiValue, i);
//NSLog(@"Email for %@: %@", label, value);
[pastUrls addObject:value];
}
}
Regards,
sathish
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这里有一些在线教程应该会有所帮助:
http ://iphone.zcentric.com/2008/09/19/access-the-address-book/
https://developer.apple.com/iphone/library/documentation/ContactData/Conceptual/AddressBookProgrammingGuideforiPhone/100-Introduction/Introduction.html
There are a couple of online tutorials here that should help:
http://iphone.zcentric.com/2008/09/19/access-the-address-book/
https://developer.apple.com/iphone/library/documentation/ContactData/Conceptual/AddressBookProgrammingGuideforiPhone/100-Introduction/Introduction.html
Apple 的 iOS 通讯簿编程指南< /a> 包含一个示例项目,可帮助您了解访问地址簿数据(包括电子邮件地址)的一般原则。
Apple's Address Book Programming Guide for iOS includes a sample project that will get you started with general principles for accessing address book data, including email addresses.