Get image of a person from iPhone address book

后端 未结 3 1207
花落未央
花落未央 2021-01-04 00:33

How do you get a person\'s image from an iPhone address book?

相关标签:
3条回答
  • 2021-01-04 00:44

    You can do it like this....

    NSData  *imgData = (NSData *)ABPersonCopyImageData(person);
    
    UIImage  *img = [UIImage imageWithData:imgData];
    

    where person is of type ABRecordRef. Now, as CFData and NSData are toll-free bridged, you can simply type cast CFData to NSData and get the image

    Hope this helps.

    0 讨论(0)
  • 2021-01-04 00:49

    Slightly refreshed code:

    UIImage *image = nil;
    
    @try
    {
        CFDataRef cfImage = ABPersonCopyImageData(person);
        // or CFDataRef cfImage = ABPersonCopyImageDataWithFormat(person, kABPersonImageFormatThumbnail);
        if (cfImage)
        {
            image = [UIImage imageWithData:(__bridge NSData*)cfImage];
            CFRelease(cfImage);
        }
    }
    @catch (NSException *exception)
    {
        //...
    }
    
    0 讨论(0)
  • 2021-01-04 00:52
    (NSData*)ABPersonCopyImageDataWithFormat([targetPeople objectAtIndex:index], kABPersonImageFormatThumbnail)
    

    This is faster since it returns a thumbnail.

    0 讨论(0)
提交回复
热议问题