我正在将应用程序文档目录中的 vcf 文件中的 vcard 数据检索到字符串中。该字符串很好,但ABPersonCreatePeopleInSourceWithVCardRepresentation
会引发 BAD_ACCESS 错误。这是代码...
ABRecordRef defaultSource = ABAddressBookCopyDefaultSource(addressBook);
NSData *data=[vcardString dataUsingEncoding:NSUTF8StringEncoding];
CFDataRef vCardData = (__bridge CFDataRef)data;
ABAddressBookRequestAccessWithCompletion(addressBook, ^(bool granted, CFErrorRef error) {
if(granted)
{
NSLog(@"%@",vcardString);
CFArrayRef vCardPeople = ABPersonCreatePeopleInSourceWithVCardRepresentation(defaultSource, vCardData);//BAD_ACCESS ERROR
for (CFIndex index = 0; index < CFArrayGetCount(vCardPeople); index++) {
ABRecordRef person = CFArrayGetValueAtIndex(vCardPeople, index);
ABAddressBookAddRecord(addressBook, person, NULL);
NSLog(@"added");
}
CFRelease(vCardPeople);
CFRelease(defaultSource);
ABAddressBookSave(addressBook, NULL);
}
else
NSLog(@"not granted");
这是 NSLog vcardString...
BEGIN:VCARD
VERSION:3.0
PRODID:-//Apple Inc.//iOS 6.1//EN
N:;Home;;;
FN:Home
EMAIL;type=INTERNET;type=HOME;type=pref:carljosdsdsewhnson.akasdssh@gmail.com
TEL;type=CELL;type=VOICE;type=pref:2323454645
PHOTO;ENCODING=b;TYPE=JPEG:/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAICAgICAQICAgIC
....LOT OF GIBBERISH....
END:VCARD