我想要做的就是让用户从地址簿中选择一个号码.我在这个问题中找到了代码:
ABMultiValueRef container = ABRecordCopyValue(person, property);
CFStringRef contactData = ABMultiValueCopyValueAtIndex(container, identifier);
CFRelease(container);
NSString *contactString = [NSString stringWithString:(NSString *)contactData];
CFRelease(contactData);
Run Code Online (Sandbox Code Playgroud)
问题是在第二行(在3.0设备上运行时)我收到以下错误:
客户经理无法找到标识为MobileMe:rustyshelf的帐户
其次是:
程序接收信号:"EXC_BAD_ACCESS".
这都在picker委托方法中:
- (BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person property:(ABPropertyID)property identifier:(ABMultiValueIdentifier)identifier{
Run Code Online (Sandbox Code Playgroud)
这只是我的地址簿中的一个联系人,它与Mobile Me同步
编辑:我认为这可能是SDK的一个错误,它发生在我的一些联系人,而不是其他人...
小智 29
"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;
}
Run Code Online (Sandbox Code Playgroud)
dr_*_*per 16
关于JWD的回答,这是一个更安全的版本,它使用内置常量并选择iphone号码而不是另一个手机号码......
ABMultiValueRef phones =(NSString*)ABRecordCopyValue(person, kABPersonPhoneProperty);
NSString* mobile=@"";
NSString* mobileLabel;
for(CFIndex i = 0; i < ABMultiValueGetCount(phones); i++) {
mobileLabel = (NSString*)ABMultiValueCopyLabelAtIndex(phones, i);
if([mobileLabel isEqualToString:(NSString *)kABPersonPhoneMobileLabel])
{
[mobile release] ;
mobile = (NSString*)ABMultiValueCopyValueAtIndex(phones, i);
}
else if ([mobileLabel isEqualToString:(NSString*)kABPersonPhoneIPhoneLabel])
{
[mobile release] ;
mobile = (NSString*)ABMultiValueCopyValueAtIndex(phones, i);
break ;
}
}
Run Code Online (Sandbox Code Playgroud)
小智 6
- (BOOL)personViewController:(ABPersonViewController *)personViewController shouldPerformDefaultActionForPerson:(ABRecordRef)person property:(ABPropertyID)property identifier:(ABMultiValueIdentifier)identifierForValue
{
if (property == kABPersonPhoneProperty)
{
ABMultiValueRef numbers = ABRecordCopyValue(person, property);
NSString* targetNumber = (__bridge NSString *) ABMultiValueCopyValueAtIndex(numbers, ABMultiValueGetIndexForIdentifier(numbers, identifierForValue));
NSLog(@"%@", targetNumber);
}
return NO;
}
Run Code Online (Sandbox Code Playgroud)
我用这个问题来构建我自己的解决方案.我发布的代码不是作为答案,仅仅是为了找到有用的人.这些是获取房产的简单步骤.内存管理除外.
您应该能够执行以下操作:
ABMultiValueRef phoneNumbers = (ABMultiValueRef)ABRecordCopyValue(person, kABPersonPhoneProperty);
CFRelease(phoneNumbers);
NSString* phoneNumber = (NSString*)ABMultiValueCopyValueAtIndex(phoneNumbers, 0);
Run Code Online (Sandbox Code Playgroud)
当然,这只会让您获得与被选中的人相关的(可能)许多个中的第一个数字。
| 归档时间: |
|
| 查看次数: |
27771 次 |
| 最近记录: |