我在从通讯簿中检索一组特定数据时遇到问题。这是代码:
- (void) getContacts{
ABAddressBookRef ab = ABAddressBookCreate();
NSMutableArray *retVal = (__bridge NSMutableArray *)(ABAddressBookCopyArrayOfAllPeople(ab));
CFRelease(ab);
contact* temp=[[contact alloc] init];
NSMutableArray* tempArray=[[NSMutableArray alloc]init];
for(int i=0;i<[retVal count];i++)
[tempArray insertObject:
[NSString stringWithFormat:@"%@",
[temp set2:[NSString stringWithFormat:@"%@",
[[retVal objectAtIndex:i] kABPersonFirstNameProperty]]
last:[NSString stringWithFormat:@"%@",
[[retVal objectAtIndex:i] kABPersonLastNameProperty]]
number:[NSString stringWithFormat:@"%@",
[[retVal objectAtIndex:i] kABPersonPhoneProperty]]]] atIndex:i];
_objects=tempArray;
[self alert:[NSString stringWithFormat:@"%@",_objects] title:@"TEMP"];
}
我得到的错误是关于 kABPerson 属性的。
更多说明:基本上我将地址簿中的所有数据抓取到第一个数组中,然后我手动遍历该数组并尝试检索我的应用程序其余部分所需的数据。
有任何想法吗?
Just for more clarification here's my contact.h file:
@interface contact : NSString{
NSString* first;
NSString* last;
NSString* number;
}
@end
这是我的contact.m文件:
@implementation contact
- (void) set:(NSString*)first2 last:(NSString*)last2 number:(NSString*)number2{
first=first2;
last=last2;
number=number2;
}
- (contact*) set2:(NSString*)first2 last:(NSString*)last2 number:(NSString*)number2{
first=first2;
last=last2;
number=number2;
return self;
}
@end
这是那条似乎太长而无法发布的行:
//Enter contact into tempArray
[tempArray insertObject:[NSString stringWithFormat:@"%@",[temp set:[NSString stringWithFormat:@"%@",(__bridge NSString *)(ABRecordCopyValue((__bridge ABMultiValueRef)[retVal objectAtIndex:i],kABPersonFirstNameProperty))] last:[NSString stringWithFormat:@"%@",(__bridge NSString *)(ABRecordCopyValue((__bridge ABMultiValueRef)[retVal objectAtIndex:i],kABPersonLastNameProperty))] number:(__bridge NSString *)ABMultiValueCopyValueAtIndex((__bridge ABMultiValueRef)((__bridge NSString*)ABRecordCopyValue((__bridge ABRecordRef)([retVal objectAtIndex:i]),kABPersonPhoneProperty)), 0)]] atIndex:i];