I am new to objective C and I am in a position where I need create an App urgently . I am using XCode 4.2
in a part of the App I will be detecting a QR code and getting a VCard in NSString format : I did the function using the following code : -I imported the following to frameworks :
AddressBookUI.framework
AddressBook.framework
在档案中,我写道:
#import <addressBook/AddressBook.h>
#import <AddressBookUI/AddressBookUI.h>
@interface HellowWorld : UIViewController<ABPeoplePickerNavigationControllerDelegate>{
}
-(IBAction)saveContacts;
@end
我在文件一中写道:
-(IBAction)saveContacts{
NSString *vCardString = test //where the data will be comming from
CFDataRef vCardData = (CFDataRef)[vCardString dataUsingEncoding:NSUTF8StringEncoding]; ABAddressBookRef book = ABAddressBookCreate();
ABRecordRef defaultSource = ABAddressBookCopyDefaultSource(book);
CFArrayRef vCardPeople = ABPersonCreatePeopleInSourceWithVCardRepresentation(defaultSource, vCardData);
for (CFIndex index = 0; index < CFArrayGetCount(vCardPeople); index++) {
ABRecordRef person = CFArrayGetValueAtIndex(vCardPeople, index);
ABAddressBookAddRecord(book, person, NULL);
CFRelease(person);
}
CFRelease(vCardPeople);
CFRelease(defaultSource);
ABAddressBookSave(book, NULL);
CFRelease(book);
}
我使用了这一法典,但并未奏效。
首先,它没有汇编这一行文:
CFDataRef vCardData = (CFDataRef)[vCardString dataUsingEncoding:NSUTF8StringEncoding];
I had to change it to this :
CFDataRef vCardData = (__bridge CFDataRef)[vCardString dataUsingEncoding:NSUTF8StringEncoding];
并在此线上对坠毁事件进行汇编之后:
for (CFIndex index = 0; index < CFArrayGetCount(vCardPeople); index++) {
It gives the following green error : Thread1: Program Received Signal "EXC_BAD_ACCESS"
.
Any reasons?
在地址簿中,这还是拯救VCard(以NSString格式)的唯一途径? 是否有任何其他建议?