English 中文(简体)
VCard 不工作的读者
原标题:VCard reader not working

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格式)的唯一途径? 是否有任何其他建议?

问题回答

我假定你能够使非洲排雷中心发挥作用。

http://www.un.org/Depts/DGACM/index_chinese.htm 数据标的在范围结束前可能仅存亡。

或许更好,使用<代码>bridge_retained

See

向电话联系清单输入Vcard数据如下。

增加AddressbookUi.framework

http://www.ohchr.org。

包括这一负责人:

#include AddressBook/ABAddressBook.h>
#include AddressBook/ABRecord.h>
#include AddressBook/ABSource.h>

并称这一职能:

-(void)importVcard {

    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *startPath = [paths objectAtIndex:0]; 
    NSString *filename  = @"contacts.vcf";
    NSString *filePath = [NSString stringWithFormat:@"%@/%@",startPath,filename];
    NSLog(@"File Path is %@",startPath);

    NSString *vCardString = [NSString stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:nil ];

    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); 
}




相关问题
List Contents of Directory in a UITableView

I am trying to list the contents of Ringtones directory in a TableView, however, I am only getting the last file in the directory in ALL cells, instead of file per cell. This is my code: - (...

iPhone NSUserDefaults persistance difficulty

In my app i have a bunch of data i store in the NSUserdefaults. This information consists of an NSObject (Object1) with NSStrings and NSNumbers and also 2 instances of yet another object (Object2). ...

Writing a masked image to disk as a PNG file

Basically I m downloading images off of a webserver and then caching them to the disk, but before I do so I want to mask them. I m using the masking code everyone seems to point at which can be found ...

Resize UIImage with aspect ratio?

I m using this code to resize an image on the iPhone: CGRect screenRect = CGRectMake(0, 0, 320.0, 480.0); UIGraphicsBeginImageContext(screenRect.size); [value drawInRect:screenRect blendMode:...

Allowing interaction with a UIView under another UIView

Is there a simple way of allowing interaction with a button in a UIView that lies under another UIView - where there are no actual objects from the top UIView on top of the button? For instance, ...

热门标签