ios - 分配parentGroup时CNContactViewController为空

标签 ios swift cncontactviewcontroller

鉴于以下情况:

let contactStore = CNContactStore()
let groupId = '<a valid group ID>'
let keysToFetch = [ // removed for brevity ]
var group: CNGroup? = nil

do {
  let predicate = CNGroup.predicateForGroups(withIdentifiers: [groupId])
  group = try contactStore.groups(matching: predicate).first
} catch let error as NSError {
  callback([error.localizedDescription, false])
}

let contactController = CNContactViewController(forNewContact: nil)
contactController.parentGroup = group
contactController.contactStore = contactStore
contactController.delegate = self
contactController.allowsEditing = true
contactController.allowsActions = true
contactController.displayedPropertyKeys = keysToFetch

当 Controller 通过以下方式显示时:

self.contactController = contactController

let navigationController = UINavigationController(rootViewController: contactController)
self.navigationController = navigationController

var currentViewController = UIApplication.shared.keyWindow?.rootViewController
while((currentViewController?.presentedViewController) != nil) {
  currentViewController = currentViewController?.presentedViewController
}

DispatchQueue.main.async(execute: {
  currentViewController?.present(navigationController, animated: true) {
    contactController.navigationItem.leftBarButtonItem = UIBarButtonItem.init(barButtonSystemItem: UIBarButtonSystemItem.cancel, target: self, action: #selector(self.cancelButtonPressed))
  }
})

呈现的CNContactViewController()是空白的:

enter image description here

我做错了什么?关于 parentGroup 的文档非常稀疏。

最佳答案

去掉这段代码,它就会起作用:

contactController.displayedPropertyKeys = keysToFetch

关于ios - 分配parentGroup时CNContactViewController为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46051229/

相关文章:

swift 3 : Share Button of Facebook SDK is Disabled

ios - 在容器 View 中显示 CNContactPickerViewController?

ios - swift 3 : CNcontactpicker's phonenumber return 'not fetched' in device

ios - UICollectionView 单元格自动调整大小

ios - 单例改变整数

ios - Swift 手动旋转 View Controller

objective-c - objective-c :如果我使用前向GeoCoding(Google API),可以为我的应用程序收取费用吗?

swift - 我可以使 SCNBox 可点击并进行交互吗?

objective-c - 向 obj c 和 swift 中的默认对象添加方法

ios - 多选联系人的 CNContactPickerViewController UI 更改