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

﹥>﹥吖頭↗ 提交于 2019-12-10 11:46:52

问题


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)")
}

回答1:


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


来源:https://stackoverflow.com/questions/33514970/cnsaverequest-addgroup-and-deletegroup-dont-immediately-change-groups-in-contac

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!