我使用联系人框架来获取用户联系人的姓名、号码、电子邮件和联系人图像,正在获取数据。我现在能够显示的只是表格视图中的一个键,例如姓名号码或电子邮件,我希望单击该名称,然后转到显示其余属性的另一个视图控制器向上。但我无法在另一个上显示它viewController
。我已经尝试在prepareforsegue
函数中使用 get contacts 方法,似乎没有工作我用来获取的代码contacts
是
func getContacts() {
let store = CNContactStore()
if CNContactStore.authorizationStatusForEntityType(.Contacts) == .NotDetermined {
store.requestAccessForEntityType(.Contacts, completionHandler: { (authorized: Bool, error: NSError?) -> Void in
if authorized {
self.retrieveContactsWithStore(store)
}
})
} else if CNContactStore.authorizationStatusForEntityType(.Contacts) == .Authorized {
self.retrieveContactsWithStore(store)
}
tableView.reloadData()
}
func retrieveContactsWithStore(store: CNContactStore) {
do {
let groups = try store.groupsMatchingPredicate(nil)
// let predicate = CNContact.predicateForContactsInGroupWithIdentifier(groups[0].identifier)
let containerId = CNContactStore().defaultContainerIdentifier()
let predicate: NSPredicate = CNContact.predicateForContactsInContainerWithIdentifier(containerId)
let keysToFetch = [CNContactFormatter.descriptorForRequiredKeysForStyle(.FullName), CNContactEmailAddressesKey, CNContactPhoneNumbersKey,CNContactImageDataAvailableKey,CNContactThumbnailImageDataKey]
print(CNContactEmailAddressesKey.capitalizedString)
let contacts = try store.unifiedContactsMatchingPredicate(predicate, keysToFetch: keysToFetch)
self.objects = contacts
dispatch_async(dispatch_get_main_queue(), { () -> Void in
self.tableView.reloadData()
})
} catch {
print(error)
}
}
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if let identifier = segue.identifier {
if identifier == "DetailContact" {
}
}
}