ABPersonSetImageData未设置联系人的来电呼叫的全尺寸图像

时间:2012-10-20 22:45:24

标签: iphone xcode abaddressbook abperson uiimagepngrepresentation

我可以在iPhone地址簿中设置新联系人的缩略图图像,但是当该联系人呼叫我的手机时,手机不会显示全屏版本。相反,它只在屏幕顶部显示缩略图版本,我的手机屏幕保护程序在后台。是否有一些我需要忘记的特殊事项(请参阅下面的代码片段)?

此外,我确实发现之前的帖子表明没有为联系人保存以前的图片,但这仍然无法解决我的问题......

提前致谢!

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

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

1 个答案:

答案 0 :(得分:1)

尝试使用以下代码将图像裁剪为完整尺寸

 -(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);
 }

然后保存

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