CNSaveRequest.addGroup和deleteGroup不会立即更改联系人中的组 [英] CNSaveRequest.addGroup and deleteGroup don't immediately change Groups in Contacts

查看:167
本文介绍了CNSaveRequest.addGroup和deleteGroup不会立即更改联系人中的组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Swift中,当您通过将 CNSaveRequest 传递给 CNContactStore 来更新联系人时,更新将立即更改您的本机联系人应用程序。

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

但是,当您通过传递<$来添加或删除 Group( CNGroup )时c $ c> CNSaveRequest 到 CNContactStore ,添加或删除操作不会立即更改本地联系人应用中的网上论坛。

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?

例如,对于代码A,您可以立即在本地联系人应用程序中看到更改。如果是代码B,则无法立即看到更改,因此必须重新启动应用程序或本机联系人应用程序。

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.

我不使用 ABAddressbook ,因此自然而然地我们在谈论iOS9。

I don't use ABAddressbook, so naturally we are talking about 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)")
}


推荐答案

对不起,但我自己解决了此问题...
我添加了刷新<$的代码 UITableView 的c $ c> dataSource ,其中显示了 CNGroup 数组。例如,...

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

这篇关于CNSaveRequest.addGroup和deleteGroup不会立即更改联系人中的组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆