ABPersonSetImageData Does Not Set Contact's Full Size Image for Incoming Calls

400 views Asked by At

I am able to set a new contact's thumbnail image in the iPhone address book, however, the phone does not display a full screen version when that contact calls my phone. Instead, it only displays the thumbnail version on top of the screen, with my phone's screen saver in the background. Is there something special that needs to be done that I am forgetting (see code snippet below)?

Also, I did find a previous post that indicated no previous image could be saved for a contact, yet this still does not fix my problem...

Thanks in Advance!

UIImage *profileImage = [[UIImage alloc] initWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:picImageUrl]]];

NSData *profileImageDataRef = UIImagePNGRepresentation(profileImage);
ABPersonSetImageData(newPerson, (__bridge CFDataRef)profileImageDataRef, nil);
1

There are 1 answers

0
Rahul Katariya On

Try cropping the image to the full size with the following code

 -(NSData *)dataFromImageData:(NSData *)imageData {
     UIImage *image = [UIImage imageWithData:imageData];
     if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)]) {
         UIGraphicsBeginImageContextWithOptions([UIScreen mainScreen].bounds.size, YES, 0.0);
     } else {
         UIGraphicsBeginImageContext([UIScreen mainScreen].bounds.size);
     }
     [image drawInRect:[UIScreen mainScreen].bounds];
     UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
     UIGraphicsEndImageContext();
     return UIImageJPEGRepresentation(newImage, 0);
 }

and then save it

NSData *dataRef = [self dataFromImageData:imageData];
CFDataRef cfdata = CFDataCreate(NULL, [dataRef bytes], [dataRef length]);
ABPersonSetImageData(aContact, cfdata, NULL);