方法如下:
-(id)getValueForProperty:(NSUInteger) propertyId{
if(personRec != NULL)
return (id)ABRecordCopyValue(personRec, (ABPropertyID)propertyId);
}
}我按以下方式调用上述方法:
NSString *lastName = (NSString *)[self getValueForProperty:kABPersonLastNamePhoneticProperty];
//or
NSString *lastName = (NSString *)[self getValueForProperty:kABPersonLastNameProperty];
NSString *firstName = (NSString *)[self getValueForProperty:kABPersonFirstNamePhoneticProperty];
//or
NSString *firstName = (NSString *)[self getValueForProperty:kABPersonFirstNameProperty];
NSString *orgName = (NSString *)[self getValueForProperty:kABPersonOrganizationProperty];但是当我在设备中运行应用程序时,它显示出它正在崩溃
return (id)ABRecordCopyValue(personRec, (ABPropertyID)propertyId); 在什么情况下这会崩溃?
发布于 2013-08-18 19:15:13
在调用ABMultiValueRef时,可能会为您的propertyId之一返回一个ABRecordCopyValue,但是您尝试将其填充到NSString中。
在这种情况下,您应该做什么(假设您正在尝试获取第一个电子邮件地址,并且正在使用ARC):
ABMultiValueRef emails = ABRecordCopyValue(person, kABPersonEmailProperty);
int no = ABMultiValueGetCount(emails);
if ( no > 0 )
{
CFStringRef emailRef = ABMultiValueCopyValueAtIndex(emails, 0);
NSString* email = CFBridgingRelease(emailRef);
}https://stackoverflow.com/questions/7610022
复制相似问题