cncontactstore

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)

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

CNContactStoreDidChangeNotification is fired multiple times

為{幸葍}努か 提交于 2019-11-30 07:57:51
I am able to observe the CNContactStoreDidChangeNotification when the contact database is changed while the app is in background state. I am pretty sure that only one observer was added to NSNotificationCenter . The problem is NSNotificationCenter posts MULTIPLE times (2, 3, 5, and even more times) even if I only add one new contact. Where is the problem? Make certain you aren't adding the observer multiple times. This can happen without you realizing it if (for example) you call -addObserver from -viewDidLoad or -viewDidAppear in your view controller (as these might get called more than once

Keyboard overlaying action sheet in iOS 13.1 on CNContactViewController

本秂侑毒 提交于 2019-11-28 00:35:20
问题 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. 回答1: 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