以下是方法:
-(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);
在什么情况下会崩溃?
答案 0 :(得分:0)
在调用 ABRecordCopyValue 时,可能会为您的一个propertyId返回 ABMultiValueRef ,但是您尝试将其填入NSString。
在这种情况下你应该做什么(说你试图获得第一个电子邮件地址并且你正在使用ARC):
ABMultiValueRef emails = ABRecordCopyValue(person, kABPersonEmailProperty);
int no = ABMultiValueGetCount(emails);
if ( no > 0 )
{
CFStringRef emailRef = ABMultiValueCopyValueAtIndex(emails, 0);
NSString* email = CFBridgingRelease(emailRef);
}