Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
594 views
in Technique[技术] by (71.8m points)

iphone - ABPersonSetImageData Only Altering the Contact Thumbnail and Not the Full Pic

I am trying to add a border around each contact photo. I have working code to create this bordered image and working code to set it as the contact image:

if (image) {
    NSData *dataRef = UIImagePNGRepresentation(image); 
    CFDataRef cfdata = CFDataCreate(NULL, [dataRef bytes], [dataRef length]);
    CFErrorRef error;
    ret = ABPersonSetImageData(person, cfdata, &error);
    if (ret) {
        ret = ABAddressBookSave(addressBook, &error);
    } else {
        DebugLog(@"Could not write the image to the person: %@", [error description]);
    }
    CFRelease(cfdata);
}

The problem I am seeing is that while the bordered image shows up correctly in the thumbnail when viewing in the Contacts or Phone app, the full-screen image displayed on an incoming call is not.

I originally thought it was just zoomed in a little so I experimented with the border size. I confirmed that the border is not showing at all on the large shot. Am I missing something obvious?


EDIT 10/9/09 I have been in communications with Apple and this is indeed a bug in the Address Book framework. If you are reading this post, then I suggest you file a bug with Apple at to help expedite the fix.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I am going to answer my own question here as I think I figured out what is the issue. If your contact does NOT already have an image, both the thumbnail and the full sized shot will be added when you use ABPersonSetImageData. If your contact has a full-sized image already, ONLY the thumbnail will be set when you use ABPersonSetImageData.

After realizing this, the solution is a no-brainer. I just remove the pic right before setting it.

if (image) {
    NSData *dataRef = UIImagePNGRepresentation(image); 
    CFDataRef cfdata = CFDataCreate(NULL, [dataRef bytes], [dataRef length]);
    CFErrorRef error;

    ABPersonRemoveImageData(person, &error); // <-- clean any image first from ref
    ABAddressBookSave(addressBook, &error);
                
    ret = ABPersonSetImageData(person, cfdata, &error);
    if (ret) {
        ret = ABAddressBookSave(addressBook, &error);
    } else {
        DebugLog(@"Could not write the image to the person");
    }
    CFRelease(cfdata);
}

NOTE*

This creates a square version of the full-sized pic. The process crops the top and bottom off of the image and sets it to be 320x320. But, it is working.

EDIT 10/9/09

I have been in communications with Apple and this is indeed a bug in the Address Book framework. If you are reading this post, then I suggest you file a bug with Apple at to help expedite the fix.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...