приложение с доступом к контактам? Не могу найти как реализовать подобный функционал.
Буду рад любой помощи. За помощь с меня 🍺
import Contacts let status = CNContactStore.authorizationStatus(for: .contacts) if status == .denied || status == .restricted { // presentSettingsActionSheet() return } let store = CNContactStore() store.requestAccess(for: .contacts) { granted, error in guard granted else { DispatchQueue.main.async { // self.presentSettingsActionSheet() } return } // get the contacts var contacts = [CNContact]() let request = CNContactFetchRequest(keysToFetch: [ CNContactIdentifierKey as NSString, CNContactFormatter.descriptorForRequiredKeys(for: .fullName), CNContactPhoneNumbersKey, CNContactPostalAddressesKey, CNContactEmailAddressesKey ] as! [CNKeyDescriptor]) do { try store.enumerateContacts(with: request) { contactsArray, stop in contacts.append(contactsArray) } } catch { print(error) } for contact in contacts { print("\(contact.familyName) \(contact.givenName) \(contact.phoneNumbers.first!.value.stringValue) \(contact.postalAddresses.first!.value.street) \(contact.emailAddresses.first?.value ?? "")") } }
Обсуждают сегодня