2

Using the ABPersonCreateVCardRepresentationWithPeople method for export, and the ABPersonCreatePeopleInSourceWithVCardRepresentation for import, I have successfully transfered contact data between devices. However, the data in the contact's "notes" field isn't transfered. Here's my export function:

+(NSData*)exportContactsToVcard:(NSArray*)contacts
{
    NSMutableArray *people  = [NSMutableArray arrayWithCapacity:contacts.count];
    ABAddressBookRef ab = ABAddressBookCreate();
    for (Contact *contact in contacts) 
    {
        ABRecordRef person = ABAddressBookGetPersonWithRecordID(ab,contact.contactId);
        [people addObject:(__bridge id)person];
    }
    NSData *vCard = (__bridge NSData*)ABPersonCreateVCardRepresentationWithPeople((__bridge CFArrayRef) people);
    return vCard;
}

and part of my import function:

+(NSArray*)importContactsFromVcardData:(NSData*)vcardData
{
    NSMutableArray *addedContactIds = [NSMutableArray array];
    ABAddressBookRef addressBook = ABAddressBookCreate();
    ABRecordRef defaultSource = ABAddressBookCopyDefaultSource(addressBook);
    NSArray *createdPeople = (__bridge_transfer NSArray*)ABPersonCreatePeopleInSourceWithVCardRepresentation(defaultSource,(__bridge CFDataRef)vcardData);
    CFErrorRef error = NULL;
    for (id person in createdPeople)
    {
        error = NULL;
        ABRecordRef personRecord = (__bridge ABRecordRef)person;
        NSString *notes = (__bridge NSString *)ABRecordCopyValue(personRecord, kABPersonNoteProperty);

In the last line, notes is always nil, even if the contact had notes before it was exported. All the other standard contact fields seem to be in place. For example, if I replace the last line with:

NSString *firstName = (__bridge NSString *)ABRecordCopyValue(personRecord, kABPersonFirstNameProperty);

the firstName string will hold the contact's first name.

Any idea how I can work around this, and get the contact notes?

Thanks.

4

2 回答 2

1

出于测试目的,您可以从通讯簿中导出 vCard。然后将其拖到 TextEdit 以查看各个字段。

在底部你会发现这样的东西:

注意:这是一个注释!

此外,有关 vCard 格式的信息,请参阅此链接:

http://en.wikipedia.org/wiki/VCard

于 2012-08-28T04:25:36.553 回答
0

ABPersonCreateVCardRepresentationWithPeople will only transfer the important contact details of a vCard...thats my identifying in much tests with the vCard and the iOS import-export function. It has many mistakes, e.g. if you try to import it with social networks like facebook, it won't do it with (just look in my other thread THREADLINK )

But if you try to add some vCard Information over ABNewPersonViewController, it will work perfectly.

于 2013-02-06T16:43:02.777 回答