CNSaveRequest.addGroup和deleteGroup不会立即更改“联系人”中的“组”
在Swift中,当您通过将CNSaveRequest
传递给CNSaveRequest
来更新“联系人”时,更新会立即更改您的本机联系人应用程序中的联系人。
但是,当您通过将CNSaveRequest
传递给CNSaveRequest
来添加或删除“Group”( CNGroup
)时,添加或删除不会立即更改本机Contacts应用程序中的Groups。
如果添加或删除“组”,您必须终止并重新启动应用程序或本机联系人应用程序。
有没有办法立即更改本机联系人应用程序中的组?
例如,在代码A的情况下,您可以立即看到本机联系人应用程序中的更改。 如果是代码B,您无法立即看到更改,您必须重新启动应用程序或本机联系人应用程序。
我不使用ABAddressbook
,所以我们自然而然地谈论iOS9。
[代码A]
let req = CNSaveRequest() req.updateContact(fooContact) do { try contactStore.executeSaveRequest(req) } catch { print("\(error)") }
[代码B]
let req = CNSaveRequest() req.addGroup(mutableGroup) do { try contactStore.executeSaveRequest(req) } catch { print("\(error)") }
抱歉,我自己解决了这个问题…我添加了刷新显示CNGroup
数组的UITableView
的dataSource
的代码。 例如,…
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 { } }