iOS Swift CNContactPickerViewController search contact and add to selection

后端 未结 4 1650
星月不相逢
星月不相逢 2020-12-31 04:02

I am using iOS 9 and Swift 2.2

I have implemented iOS inbuilt CNContactPickerViewController using CNContactPickerDelegate to get the cont

4条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-31 04:57

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

提交回复
热议问题