我目前正在创建一些使用ABRecordRefs数据建模的对象 - 所以我解析出来代表名字,电子邮件的字符串。我确实需要对实际的ABRecord的引用,因为在某些时候我会将它传递给ABPErsonViewController。
因此,如果将ABRecord指定为我的对象的属性,似乎我会引用它。但是当我把它传递给控制器时,我对该记录的访问权限很差。当我在调试器中检查它时,它似乎存在 - 至少它不是零。
有什么想法吗?我应该将记录标识符用作属性并重新查看并获取记录,然后将其交给ABPersonViewController吗?有点好奇为什么它不起作用。
- (NSArray*)allContacts
{
ABAddressBookRef addressBook = ABAddressBookCreateWithOptions(NULL, NULL);
CFArrayRef people = ABAddressBookCopyArrayOfAllPeople(addressBook);
NSInteger count = ABAddressBookGetPersonCount(addressBook);
NSMutableArray *contacts = [NSMutableArray array];
for (int i = 0; i < count; i++) {
ABRecordRef record = CFArrayGetValueAtIndex(people, i);
ABRecordType type = ABRecordGetRecordType(record);
NSLog(@"Type = %i", type);
ALContact *contact = [[ALContact alloc] initWithRecord:record];
[contacts addObject:contact];
}
CFRelease(addressBook);
CFRelease(people);
return contacts;
}
- (instancetype)initWithRecord:(ABRecordRef)record
{
if (self = [super init]) {
_firstName = (__bridge_transfer NSString *)ABRecordCopyValue(record, kABPersonFirstNameProperty);
_lastName = (__bridge_transfer NSString *)ABRecordCopyValue(record, kABPersonLastNameProperty);
_compositeName = (__bridge_transfer NSString *)ABRecordCopyCompositeName(record);
_record = record;
NSData *imageData = (__bridge_transfer NSData *)ABPersonCopyImageDataWithFormat(record, kABPersonImageFormatThumbnail);
_thumbnailImage = [UIImage imageWithData:imageData];
_emailAddresses = [self parseEmailValuesForRecord:record];
_phoneNumbers = [self parsePhoneNumberValuesForRecord:record];
_socialProfiles = [self parseSocialProfileValuesForRecord:record];
}
return self;
}