开发者

How to save image to iphone's AddressBook using SDK API?

My purpose is to process one image from image library, and save this image directly to one person record (i,e, "Tom" ), which is selected from AddressBook, I can see the new image replace Tom's previous image, but I can not save it to AddressBook.

I implemented delegate ABPeoplePickerNavigationControllerDelegate, and using following logics, but whatever I tried, modified records can not be saved to address books.

Any clues or suggest ? Thanks

    ABAddres开发者_开发问答sBookRef addressBook= ABAddressBookCreate();
    CFErrorRef error = NULL;
    BOOL wantToSaveChanges = YES;

    ABRecordSetValue(person, kABPersonFirstNameProperty, @"Shi", &error);//, &error)

    NSData * dataRef = UIImagePNGRepresentation(cellImage);
    ABPersonSetImageData(person, dataRef, &error);

    if (ABAddressBookHasUnsavedChanges(addressBook)) {\
        NSLog(@"need to save ");
        if (wantToSaveChanges) {
            ABAddressBookSave(addressBook, &error);
        } else {
            ABAddressBookRevert(addressBook);
        }
    }else {
        NSLog(@"no changes");
    }

    if (error != NULL) {/*... Handle error. ...*/
        NSLog(@"error happened here " );

    }

    CFRelease(addressBook);


See:

Setting Address Book image for a contact doesn't seem to work

and

ABPersonSetImageData Only Altering the Contact Thumbnail and Not the Full Pic

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜