在 iOS 5.0/XCode 4.2 中使用 VCards 和 ABAddressBook

发布于 2024-12-22 04:19:14 字数 1169 浏览 6 评论 0原文

我正在尝试保存地址簿中所有条目的副本,将其另存为 vcards 文件,然后检索该文件(或该文件的版本)并在需要时将它们添加回地址簿,在备份上下文中。我知道这个问题以前曾被问过,但对于我的生活(以及我的新手编程技能),我无法让它发挥作用:

- (void)grabContacts
{
    ABAddressBookRef addressBook = ABAddressBookCreate();
    CFArrayRef contacts = ABAddressBookCopyArrayOfAllPeople(addressBook);
    NSData *vcards = (NSData *)ABPersonCreateVCardRepresentationWithPeople(contacts);

    [vcards autorelease];

    NSError *error;
    NSFileManager *fileMgr = [NSFileManager defaultManager];


    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);  
    NSString *folderPath = [paths objectAtIndex:0]; 
    NSString *filePath = [folderPath stringByAppendingPathComponent:@"contacts.dat"];

   [NSKeyedArchiver archiveRootObject:vcards toFile:filePath];    

    NSLog(@"Documents directory: %@",
      [fileMgr contentsOfDirectoryAtPath: folderPath error:&error]);

   CFRelease(addressBook);
 }

我使用了 将联系人从一个源复制到另一个源以供接收端使用,但它不起作用,并且由于苹果方面的文档含糊不清,我已经破坏了我的脑子没有结果。

提前致谢。

S。

I am trying to save a copy of all the entries in the address book, save it to a file as vcards, and then retrieve that file (or a version of that file) and add them back to the address book when I need them, in a backing up context. I know this question has been asked before, but for the life of me (and my newbish programming skills) I can not get it to work:

- (void)grabContacts
{
    ABAddressBookRef addressBook = ABAddressBookCreate();
    CFArrayRef contacts = ABAddressBookCopyArrayOfAllPeople(addressBook);
    NSData *vcards = (NSData *)ABPersonCreateVCardRepresentationWithPeople(contacts);

    [vcards autorelease];

    NSError *error;
    NSFileManager *fileMgr = [NSFileManager defaultManager];


    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);  
    NSString *folderPath = [paths objectAtIndex:0]; 
    NSString *filePath = [folderPath stringByAppendingPathComponent:@"contacts.dat"];

   [NSKeyedArchiver archiveRootObject:vcards toFile:filePath];    

    NSLog(@"Documents directory: %@",
      [fileMgr contentsOfDirectoryAtPath: folderPath error:&error]);

   CFRelease(addressBook);
 }

I used the solution posted in Copying contacts from one source to another for the receiving end, but it doesn't work and due to the vague documentation on Apple's side I have wracked my brain for no result.

Thanks in advance.

S.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

泅渡 2024-12-29 04:19:14

没关系。我发现了我的问题。当我恢复文件时,我没有取消归档这些文件。愚蠢的我在没有大量酒精的情况下得到了愚蠢的我应得的编程。

Nevermind. I found my problem. I did not unarchive the files when I restored them. Silly me gets what silly me deserves for programming without copious amounts of alcohol.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文