cncontact

CNContact add new contact issue

断了今生、忘了曾经 提交于 2019-12-04 13:51:52
I'm faccing an issue at time of adding contacts throught Contact Framework . I used device iPhone 5s with iOS 12.1.2 My Code for adding contact is as below :: let saveRequest = CNSaveRequest() saveRequest.add(self, toContainerWithIdentifier: nil) do { try contactStore.execute(saveRequest) } catch let error { print("Error occurred while saving the request \(error)") } This everytime thows error as below :: Error occurred while saving the request Error Domain=CNErrorDomain Code=1 "Communication Error" UserInfo={NSLocalizedDescription=Communication Error, NSLocalizedFailureReason=An error

How to retrieve all contacts using CNContact.predicateForContacts?

允我心安 提交于 2019-12-04 09:58:23
So I have this code which works fine, but only if you have specified a name in the predicateForContacts parameter. func retrieveContactsWithStore(store: CNContactStore) { do { let predicate = CNContact.predicateForContacts(matchingName: "John") let keysToFetch = [CNContactFormatter.descriptorForRequiredKeys(for: .fullName), CNContactPhoneNumbersKey] as [Any] let contacts = try store.unifiedContacts(matching: predicate, keysToFetch: keysToFetch as! [CNKeyDescriptor]) self.objects = contacts DispatchQueue.main.async(execute: { () -> Void in self.myTableView.reloadData() }) } catch { print(error)

How to fetch only mobile numbers in swift using CNContacts?

*爱你&永不变心* 提交于 2019-12-04 05:17:51
I have some code to retrieve all the phone numbers in the users contacts, but would like to filter out only mobile numbers. Currently, I am just doing this by only adding numbers with a first digit of "+" or second digit of "7" to an array, as shown below: func findContacts () -> [CNContact]{ let keysToFetch = [CNContactFormatter.descriptorForRequiredKeysForStyle(.FullName),CNContactPhoneNumbersKey] let fetchRequest: CNContactFetchRequest = CNContactFetchRequest(keysToFetch: keysToFetch) var contacts = [CNContact]() CNContact.localizedStringForKey(CNLabelPhoneNumberiPhone) fetchRequest

What is the “:ABPerson” string in CNContact identifier?

我只是一个虾纸丫 提交于 2019-12-03 10:57:21
My iOS application checks contacts from time to time and imports new to its own database. I checks that contact already exists by identifier field, that usually filled by UUID: CNContactStore *store = [CNContactStore new]; [store requestAccessForEntityType:CNEntityTypeContacts completionHandler:^(BOOL granted, NSError *error) { if (granted) { NSArray *keys = @[CNContactNamePrefixKey, CNContactGivenNameKey, CNContactMiddleNameKey, CNContactFamilyNameKey, CNContactInstantMessageAddressesKey]; NSString *containerId = store.defaultContainerIdentifier; NSPredicate *predicate = [CNContact

CNContact encoding of properties

倾然丶 夕夏残阳落幕 提交于 2019-12-02 19:47:40
问题 I have a v-card string with the first name André and I initialise a CNContact with the v-card. BEGIN:VCARD VERSION:2.1 N:Foo;André;;; FN:André Foo TEL;CELL:00023 4474848 END:VCARD I initialise the contact with the raw string like this: if let data = string.data(using: .utf8) { do { let contacts = try CNContactVCardSerialization.contacts(with: data) let contact = contacts.first return contact } catch { print("Data is not a VCard") } } But when I print out the raw string of contact.givenName I

CNContact encoding of properties

北城余情 提交于 2019-12-02 11:35:44
I have a v-card string with the first name André and I initialise a CNContact with the v-card. BEGIN:VCARD VERSION:2.1 N:Foo;André;;; FN:André Foo TEL;CELL:00023 4474848 END:VCARD I initialise the contact with the raw string like this: if let data = string.data(using: .utf8) { do { let contacts = try CNContactVCardSerialization.contacts(with: data) let contact = contacts.first return contact } catch { print("Data is not a VCard") } } But when I print out the raw string of contact.givenName I get: Andr√© How can I get the proper string of the Contacts framework in iOS? You need to add a charset

Keyboard overlaying action sheet in iOS 13.1 on CNContactViewController

不问归期 提交于 2019-12-01 08:16:40
This seems to be specific to iOS 13.1, as it works as expected on iOS 13.0 and earlier versions to add a contact in CNContactViewController, if I 'Cancel', the action sheet is overlapping by keyboard. No actions getting performed and keyboard is not dismissing. Kudos to @GxocT for the the great workaround! Helped my users immensely. But I wanted to share my code based on @GxocT solution hoping it will help others in this scenario. I needed my CNContactViewControllerDelegate contactViewController(_:didCompleteWith:) to be called on cancel (as well as done). Also my code was not in a

How to get localizedstring for CNLabeledValue in swift3

余生长醉 提交于 2019-12-01 04:19:12
In swift 2 I'm using CNLabeledValue.localizedStringForLabel(phoneNumber.label) and works fine. In swift 3 I tried this line CNLabeledValue.localizedString(forLabel: phoneNumber.label!) but got generic parameter 'ValueType' could not be inferred error How to get localizedstring for CNLabeledValue in swift3? In Swift 3, CNLabeledValue is declared as: public class CNLabeledValue<ValueType : NSCopying, NSSecureCoding> : NSObject, NSCopying, NSSecureCoding { //... } It's a generic type and if you use it in a proper context, you have no need to to cast its value . Swift 3 well infers the ValueType .

How to get localizedstring for CNLabeledValue in swift3

Deadly 提交于 2019-12-01 01:21:43
问题 In swift 2 I'm using CNLabeledValue.localizedStringForLabel(phoneNumber.label) and works fine. In swift 3 I tried this line CNLabeledValue.localizedString(forLabel: phoneNumber.label!) but got generic parameter 'ValueType' could not be inferred error How to get localizedstring for CNLabeledValue in swift3? 回答1: In Swift 3, CNLabeledValue is declared as: public class CNLabeledValue<ValueType : NSCopying, NSSecureCoding> : NSObject, NSCopying, NSSecureCoding { //... } It's a generic type and if

How to sort contacts using Contacts with Swift

眉间皱痕 提交于 2019-12-01 00:22:48
问题 I've read official apple documentation about sorting contacts, although I am not sure how to implement it. So, here is fetch request: let fetchRequest = CNContactFetchRequest(keysToFetch: keysToFetch) and my prefered sort order: let sortOrder = CNContactSortOrder.UserDefault and this is how I usually fetch contacts: do { try store.enumerateContactsWithFetchRequest(fetchRequest, usingBlock: { (let contact, let stop) -> Void in self.contacts.append(contact) }) } catch let error as NSError {