Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Contacts framework raises exception on reading of imageData

I try to fetch imageData after refetching CNContact using unifiedContactWithIdentifier:keysToFetch:error: and CNContactImageDataKey in Objective-C.

I'm using Xcode 7.0 building on iPhone 6 Plus with iOS 9.0.2.

In runtime I always have the same exception CNPropertyNotFetchedException even refetching contact and checking imageData calling imageDataAvailable‌.

Here is the code:

if([currentNativeContact isKeyAvailable:CNContactImageDataKey] &&
    currentNativeContact.imageDataAvailable) {
    previewImage = [UIImage imageWithData:currentNativeContact.thumbnailImageData];
}  else {
    NSError *error;
    currentNativeContact = [self.contactsStore unifiedContactWithIdentifier:currentNativeContact.identifier keysToFetch:@[CNContactImageDataKey] error:&error];
    if(!error && currentNativeContact.imageDataAvailable)
        previewImage = [UIImage imageWithData:currentNativeContact.thumbnailImageData];                            
}
like image 245
mikthebig Avatar asked Oct 14 '15 16:10

mikthebig


1 Answers

You need to add CNContactImageDataAvailableKey, CNContactImageDataKey and CNContactThumbnailImageDataKey keys to the keysToFetch.

like image 197
Eric Avatar answered Oct 19 '22 18:10

Eric