簡體   English   中英

選擇聯系委托方法不調用

[英]Select contact delegate method not calling

在我的應用程序中,我想使用ContactsUI框架自動填充字段。 我創建了按鈕,並希望在用戶選擇一個時獲取聯系人數據:

class MyController: UIViewController,CNContactPickerDelegate {
     var contactStore = CNContactStore()
     @IBAction func selectContact(_ sender: Any) {
        self.requestForContactAccess { (accessGranted) -> Void in
            if accessGranted {
                let contactPickerViewController = CNContactPickerViewController()

                contactPickerViewController.predicateForEnablingContact = NSPredicate(format: "birthday != nil")

                contactPickerViewController.delegate = self

                self.present(contactPickerViewController, animated: true, completion: nil)

                contactPickerViewController.displayedPropertyKeys = [CNContactGivenNameKey, CNContactFamilyNameKey, CNContactEmailAddressesKey, CNContactBirthdayKey, CNContactImageDataKey]

            }
        }

    }
}

並創建方法:

func contactPicker(picker: CNContactPickerViewController, didSelectContact contact: CNContact) {
        print(contact)
    }

但選擇后,聯系人沒有打印和觸點未關閉的控制器。 我做錯了什么?

謝謝@Larme

如果您使用的是Swift 3:stackoverflow.com/questions/40491818 / ...? 該方法的Swift 3簽名是可選的func contactPicker(_ picker: CNContactPickerViewController, didSelect contact: CNContact) ,你使用的是舊的。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM