iOS Swift CNContactPickerViewController搜索联系人并添加至选择 [英] iOS Swift CNContactPickerViewController search contact and add to selection
本文介绍了iOS Swift CNContactPickerViewController搜索联系人并添加至选择的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经使用CNContactPickerDelegate
实现了iOS内置的CNContactPickerViewController
来获取联系电话
I have implemented iOS inbuilt CNContactPickerViewController
using CNContactPickerDelegate
to get the contact numbers,
在CNContactPickerViewController
屏幕中,当我单击顶部的搜索字段并搜索名称时,我需要将该名称添加到我的选择中,但是点击该联系人后什么也没有发生.
In the CNContactPickerViewController
Screen, when I click on search field on top and search for a name, I need to add that name to my selection but nothing happens after tapping the contact.
我到处搜索,并找到任何解决办法
I searched everywhere and dint find any solution to this
我是否需要在代码中添加任何内容,还是iOS 9的错误
Do I need to add anything to my code or is it a iOS 9 bug
@IBAction func AddBtnKlkFnc(sender: AnyObject)
{
let contactPicker = CNContactPickerViewController()
contactPicker.delegate = self
contactPicker.displayedPropertyKeys =
[CNContactPhoneNumbersKey]
self.presentViewController(contactPicker, animated: true, completion: nil)
}
func contactPicker(picker: CNContactPickerViewController, didSelectContacts ContctAryVar: [CNContact])
{
for ContctVar in ContctAryVar
{
let ContctDtlVar = ContctDtlCls()
ContctDtlVar.ManNamVar = CNContactFormatter.stringFromContact(ContctVar, style: .FullName)!
for ContctNumVar: CNLabeledValue in ContctVar.phoneNumbers
{
var MobNumVar = ((ContctNumVar.value as! CNPhoneNumber).valueForKey("digits") as? String)!
if(MobNumVar.Len() > 10)
{
MobNumVar = MobNumVar.GetLstSubSrgFnc(10)
}
ContctDtlVar.MobNumVar = MobNumVar
ContctDtlAryVar.append(ContctDtlVar)
}
}
}
推荐答案
Use this updated code and
@IBAction func AddBtnKlkFnc(sender: AnyObject)
{
let contactPicker = CNContactPickerViewController()
contactPicker.delegate = self
contactPicker.displayedPropertyKeys =
[CNContactPhoneNumbersKey]
self.presentViewController(contactPicker, animated: true, completion: nil)
}
func contactPicker(picker: CNContactPickerViewController, didSelectContacts ContctAryVar: [CNContact])
{
for ContctVar in ContctAryVar
{
let ContctDtlVar = ContctDtlCls()
ContctDtlVar.ManNamVar = CNContactFormatter.stringFromContact(ContctVar, style: .FullName)!
for ContctNumVar: CNLabeledValue in ContctVar.phoneNumbers
{
var MobNumVar = ((ContctNumVar.value as! CNPhoneNumber).valueForKey("digits") as? String)!
if(MobNumVar.Len() > 10)
{
MobNumVar = MobNumVar.GetLstSubSrgFnc(10)
}
ContctDtlVar.MobNumVar = MobNumVar
ContctDtlAryVar.append(ContctDtlVar)
}
}
delegate.didFetchContacts([contact])
navigationController?.popViewControllerAnimated(true)
}
这篇关于iOS Swift CNContactPickerViewController搜索联系人并添加至选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文