你如何从地址簿中获得一个人的电话号码? [英] How do you get a persons phone number from the address book?

查看:372
本文介绍了你如何从地址簿中获得一个人的电话号码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要做的就是让用户从地址簿中选择一个号码。我在这个问题中找到了代码:

All I want to do is let the user select a number from the address book. I found the code in this question:

如何从地址簿联系人(iphone sdk)获取电话号码

ABMultiValueRef container = ABRecordCopyValue(person, property);
CFStringRef contactData = ABMultiValueCopyValueAtIndex(container, identifier);
CFRelease(container);
NSString *contactString = [NSString stringWithString:(NSString *)contactData];
CFRelease(contactData);

问题是在第二行(在3.0设备上运行时)我收到以下错误:

The problem is that on the second line (when running on a 3.0 device) I get the following error:

客户经理无法找到标识符为MobileMe的帐户:rustyshelf

关注由:

程序接收到的信号: EXC_BAD_ACCESS

Program received signal: "EXC_BAD_ACCESS".

这是所有的拾取器委托方法内:

This is all inside the picker delegate method:

- (BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person property:(ABPropertyID)property identifier:(ABMultiValueIdentifier)identifier{

这只是我的地址簿中的一个联系人,它与Mobile Me同步

This is just one of the contacts in my address book, which is synched with Mobile Me

编辑:我认为这可能是SDK的一个错误,它发生在我的一些联系人身上但不适用于其他人...

I think this might be a bug with the SDK, it happens for some of my contacts but not for others...

推荐答案

identifier参数不包含CFIndex记录触动了。该方法我用来告诉哪个电话号码选择的用户是这样的:

The "identifier" argument does not hold the CFIndex of the record touched. The method I use to tell which phone number a user selected is this:

- (BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person property:(ABPropertyID)property identifier:(ABMultiValueIdentifier)identifier
{
    if (property == kABPersonPhoneProperty) {
        ABMultiValueRef multiPhones = ABRecordCopyValue(person, kABPersonPhoneProperty);
        for(CFIndex i = 0; i < ABMultiValueGetCount(multiPhones); i++) {
            if(identifier == ABMultiValueGetIdentifierAtIndex (multiPhones, i)) {
                CFStringRef phoneNumberRef = ABMultiValueCopyValueAtIndex(multiPhones, i);
                CFRelease(multiPhones);
                NSString *phoneNumber = (NSString *) phoneNumberRef;
                CFRelease(phoneNumberRef);
                txtPhoneNumber.text = [NSString stringWithFormat:@"%@", phoneNumber];
                [phoneNumber release];
            }
        }
    }

    [self dismissModalViewControllerAnimated:YES];
    return NO;
}

这篇关于你如何从地址簿中获得一个人的电话号码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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