72571

CNSaveRequest.addGroup and deleteGroup don't immediately change Groups in Contacts

Question:

In Swift, when you update "Contact" by passing CNSaveRequest to CNContactStore, the update immediately changes Contacts in your native Contacts app.

However, when you add or delete "Group" (CNGroup) by passing CNSaveRequest to CNContactStore, the addition or deletion doesn't immediately change Groups in your native Contacts app.

In case of addition or deletion of "Group", you have to terminate and restart your app or native Contacts app.

Are there any ways to immediately change Groups in native Contacts app?

For example, in case of Code A, you can immediately see the change in native Contacts app. In case of Code B, you cannot immediately see the change, you have to restart either your app or native Contacts app.

I don't use ABAddressbook, so naturally we are talking about iOS9.

[Code A]

let req = CNSaveRequest() req.updateContact(fooContact) do { try contactStore.executeSaveRequest(req) } catch { print("\(error)") }

[Code B]

let req = CNSaveRequest() req.addGroup(mutableGroup) do { try contactStore.executeSaveRequest(req) } catch { print("\(error)") }

Answer1:

Sorry, but I resolved this problem by myself... I added the code that refreshes the dataSource of UITableView that shows CNGroup array. For example,...

var groups: [CNGroup] = [] // dataSource of myTableView ...... // Custome function to be called when you want to refresh myTableView function refreshMyTableView() { do { // I forget adding the line below to refresh tableview datasource try self.groups = contactStore.groupsMatchingPredicate(nil) myTableView.reloadData() } catch { } }

Recommend

  • cant't query json data in laravel 5.2
  • how to save and retrive images from sql lite database in android
  • CNSaveRequest.addGroup and deleteGroup don't immediately change Groups in Contacts
  • Custom thread pool supporting async actions
  • Why a class has only one destructor? [duplicate]
  • Cannot terminate threads
  • How does `std::terminate` know to treat `std::exception`s specially?
  • How to issue a command that produces infinite output and return immediately
  • Regex for incomplete lines within known start and end strings
  • Avoid registering duplicate broadcast receivers in Android
  • Deploying a CodeRush plugin from the Community Site
  • Accessing Rows In A LINQ Result Without A Foreach Loop?
  • iText RadioGroup/RadioButtons across multiple PdfPCells
  • Tamper-proof configuration files in .NET?
  • PHPUnit_Framework_TestCase class is not available. Fix… - Makegood , Eclipse
  • Sony Xperia Z Tablet not found by adb
  • Javascript + PHP Encryption with pidCrypt
  • How to make Safari send if-modified-since header?
  • WOWZA + RTMP + HTML5 Playback?
  • Calling of Constructors in a Java
  • How to pass list parameters for each object using Spring MVC?
  • Traverse Array and Display in markup
  • Transpose CSV data with awk (pivot transformation)
  • Acquiring multiple attributes from .xml file in c#
  • Why can't I rebase on to an ancestor of source changesets if on a different branch?
  • How to CLICK on IE download dialog box i.e.(Open, Save, Save As…)
  • Setting background image for body element in xhtml (for different monitors and resolutions)
  • How does Linux kernel interrupt the application?
  • How can I remove ASP.NET Designer.cs files?
  • JaxB to read class hierarchy
  • java string with new operator and a literal