아직 주소록에서 사용자의 연락처 이미지를 가져 오려고했습니다. 사용자 이름을 검색 할 수 있지만 문제를 파악할 수 없습니다. 이미지.iOS 6의 주소록에서 연락처 이미지를 가져 오는 방법
이것은 내가 지금까지 시도한 것입니다.
-(void)fetchAddressBook
{
self.reterivedNamesMutableArray =[[NSMutableArray alloc]init];
ABAddressBookRef UsersAddressBook = ABAddressBookCreateWithOptions(NULL, NULL);
//contains details for all the contacts
CFArrayRef ContactInfoArray = ABAddressBookCopyArrayOfAllPeople(UsersAddressBook);
//get the total number of count of the users contact
CFIndex numberofPeople = CFArrayGetCount(ContactInfoArray);
UIImage* image;
//iterate through each record and add the value in the array
for (int i =0; i<numberofPeople; i++)
{
ABRecordRef ref = CFArrayGetValueAtIndex(ContactInfoArray, i);
ABMultiValueRef firstName = (__bridge ABMultiValueRef)((__bridge NSString*)ABRecordCopyValue(ref, kABPersonFirstNameProperty));
ABMultiValueRef lastName = (__bridge ABMultiValueRef)((__bridge NSString*)ABRecordCopyValue(ref, kABPersonLastNameProperty));
NSString *tempFirstName = (__bridge NSString *)(firstName);
NSString *tempLastName = (__bridge NSString *)(lastName);
//Compose full name
NSString *fullName = @"";
if (firstName != nil)
{
fullName = [fullName stringByAppendingString:tempFirstName];
}
if (lastName != nil)
{
fullName = [fullName stringByAppendingString:@" "];
fullName = [fullName stringByAppendingString:tempLastName];
}
if (ABPersonHasImageData(ref))
{
image = [UIImage imageWithData:(__bridge NSData *)(ABPersonCopyImageDataWithFormat(ref, kABPersonImageFormatThumbnail))];
}
else
{
image = [UIImage imageNamed:@"default.png"];
}
[self.reterivedNamesMutableArray addObject:fullName]; //Array of full name.
[self.reterivedImagesArray addObject:image]; //Array of contact images.
NSLog(@"Names array content = %@", self.reterivedNamesMutableArray);
NSLog(@"Images array content = %@", [self.reterivedImagesArray lastObject]);//This shows null
}
는 당신이 self.reterivedImagesArray 초기화 + 할당 된 좋아하지을 ? –
예, 이미 그랬습니다 ...... 시뮬레이터에서 프로젝트를 삭제하고 다시 시작했습니다 .... 그리고 지금은 작동하는 것 같습니다 ... – icodes
코드에 많은 메모리 누수가 있습니다. "Create"또는 "Copy"함수에서 반환 된 객체를'CFRelease()'하거나 적절한 위치에서'__brigde_transfer' 나'CFBridgingRelease()'를 사용해야합니다. Xcode에서 "제품 -> 분석"을 실행하고 메모리 관리 지침을 읽는 것이 좋습니다. –