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

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.

  • GPUImage Video with transparency over UIView
  • Customize apps gallery in appstore page
  • Observing Asynchronous Requests
  • tony million Reachability says unreachable when connected
  • Get HTML from safari share extension?
  • Extracting a public key from key pair in key chain
  • 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)")
    }
    

    Solutions Collect From Internet About “CNSaveRequest.addGroup and deleteGroup don't immediately change Groups in Contacts”

    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 {
        }
    }