How to fetch all contacts record in iOS 9 using Contacts Framework

前端 未结 20 1598
[愿得一人]
[愿得一人] 2020-11-28 01:52

Most part of AddressBook framework is deprecated in iOS 9. In the new Contacts Framework documentation only shows how to fetch records matches a NSPredicate, bu

20条回答
  •  迷失自我
    2020-11-28 02:18

    If you want to get ALL fields of a contact with known identifier:

    let contact = unifiedContact(withIdentifier: identifier, keysToFetch: [CNContactVCardSerialization.descriptorForRequiredKeys()])
    

    This gives you an access to ALL fields, such as adresses, phone numbers, full name, etc.

    To retrieve fullName then:

    let fullname = CNContactFormatter.string(from: contact, style: .fullName)
    

提交回复
热议问题