如何从iphone sdk中的地址簿中访问联系人图像?

时间:2010-08-14 13:50:10

标签: objective-c ios cocoa-touch

我需要从iPhone的地址簿中获取特定人物的联系人图片。任何人都可以建议如何访问它吗?

1 个答案:

答案 0 :(得分:7)

这样做......

- (BOOL)peoplePickerNavigationController: (ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person {

    // setting the first name
   // firstName.text = (NSString *)ABRecordCopyValue(person, kABPersonFirstNameProperty);

    // setting the last name
   // lastName.text = (NSString *)ABRecordCopyValue(person, kABPersonLastNameProperty);
        //NSMutableArray *people = [[[(NSArray*) ABAddressBookCopyArrayOfAllPeople(addressBook) autorelease] mutableCopy] autorelease];

    //[people sortUsingFunction:(int (*)(id, id, void *) ) ABPersonComparePeopleByName context:(void*)ABPersonGetSortOrdering()];

    UIImage* image;

        if(ABPersonHasImageData(person)){
            image = [UIImage imageWithData:(NSData *)ABPersonCopyImageData(person)];
            myima.image=image;
        }else{
            image = [UIImage imageNamed:@"contact_image.gif"];
            myima.image=image;
        }

    // setting the number
    /*
     this function will set the first number it finds

     if you do not set a number for a contact it will probably
     crash
     */
    //ABMultiValueRef multi = ABRecordCopyValue(person, kABPersonPhoneProperty);
    //number.text = (NSString*)ABMultiValueCopyValueAtIndex(multi, 0);

    // remove the controller
    [self dismissModalViewControllerAnimated:YES];

    return NO;
}