0

IOS 9s ContactUI フレームワークを使用する必要がある Swift 2.0 のプロジェクトに取り組んでいます。私が抱えている問題は、連絡先リストから電話番号を適切に選択することです。連絡先から電話番号を選択すると、アプリケーションがクラッシュします。

このタスクを実行するために使用しているコードは次のとおりです。

var delegate: NewLocationViewControllerDelegate!
var contacts = [CNContact]()

override func viewDidLoad() {
    super.viewDidLoad()
    UIApplication.sharedApplication().delegate as! AppDelegate
    // Do any additional setup after loading the view.
}//end

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}

@IBAction func openContacts(sender: UIButton) {
    let contactPicker = CNContactPickerViewController()
    contactPicker.delegate = self;
    contactPicker.displayedPropertyKeys = [CNContactPhoneNumbersKey]

    self.presentViewController(contactPicker, animated: true, completion: nil)
}//end

func contactPicker(picker: CNContactPickerViewController, didSelectContactProperty contactProperty: CNContactProperty) {
    let contact = contactProperty.contact
    let phoneNumber = contactProperty.value as! CNPhoneNumber
    print(contact.givenName)
    print(phoneNumber.stringValue)
}//end
4

1 に答える 1