关于从 iPhone 通讯录中检索所有电子邮件 ID 的问题

发布于 2024-09-12 11:31:27 字数 1069 浏览 2 评论 0原文

我是地址簿编程的新手。我想从地址簿中检索所有电子邮件 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 技术交流群。

扫码二维码加入Web技术交流群
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文