我想做的就是让用户从地址簿中选择一个号码。我在这个问题中找到了代码:
如何从地址簿联系人获取电话号码 (iphone sdk) https://stackoverflow.com/questions/286207/how-to-get-a-phone-number-from-an-address-book-contact-iphone-sdk
ABMultiValueRef container = ABRecordCopyValue(person, property);
CFStringRef contactData = ABMultiValueCopyValueAtIndex(container, identifier);
CFRelease(container);
NSString *contactString = [NSString stringWithString:(NSString *)contactData];
CFRelease(contactData);
问题是在第二行(在 3.0 设备上运行时)出现以下错误:
客户经理找不到标识符为 MobileMe:rustyshelf 的帐户
其次是:
程序收到信号:“EXC_BAD_ACCESS”。
这一切都在选择器委托方法内:
- (BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person property:(ABPropertyID)property identifier:(ABMultiValueIdentifier)identifier{
这只是我通讯录中的联系人之一,与 Mobile Me 同步
编辑:我认为这可能是 SDK 的一个错误,它发生在我的一些联系人身上,但不会发生在其他人身上......
“identifier”参数不保存所触及记录的 CFIndex。我用来判断用户选择哪个电话号码的方法是:
- (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;
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)