在swift中从ABPeoplePickerNavigationController创建Vcf文件

时间:2015-07-24 03:44:47

标签: ios swift

您好我是IOS Swift开发的新手,我想将.vcf文件发送到server.And我正在使用ABPeoplePickerNavigationController来选择联系人。以下是我正在使用的代码

  let picker = ABPeoplePickerNavigationController()
        picker.peoplePickerDelegate = self

        if picker.respondsToSelector(Selector("predicateForEnablingPerson")) {
            picker.predicateForEnablingPerson = NSPredicate(format: "emailAddresses.@count > 0")
        }

        presentViewController(picker, animated: true, completion: nil)

选择联系人后,委托方法正在解雇

  func peoplePickerNavigationController(peoplePicker: ABPeoplePickerNavigationController!, didSelectPerson person: ABRecordRef!) {
}

现在我想获取vcf数据。我怎么能得到这个,请帮助我...

1 个答案:

答案 0 :(得分:1)

最后,经过长时间的研究,我得到了答案

func peoplePickerNavigationController(peoplePicker: ABPeoplePickerNavigationController!, didSelectPerson record: ABRecordRef!) {
      let peopleArray: CFArray = [record]
      let vCardData: NSData = ABPersonCreateVCardRepresentationWithPeople(peopleArray).takeRetainedValue()
      var ok:Bool = fileManager.createFileAtPath("filePath",contents: vCardData , attributes:nil)
}

将文件另存为vcf文件,感谢堆栈溢出支持