CNContactPickerViewController
を使用して連絡先を選択できるプログラムを作成しています。選択した連絡先にNOT
の電話番号がある場合、その電話番号にエラーが表示され、OKを押すとContactPickerViewController
に戻ります。私はブレークポイントでコードを通過し、正しく実行されていますが、エラーポップアップが表示されません。私は私の人生のために理由を理解することはできませんCNContactStoreに電話番号があり、エラーポップオーバーが表示されていないか確認してください。
は...ここに私のコードは次のとおりです。
func contactPicker(_ picker: CNContactPickerViewController, didSelect contact: CNContact) {
if contact.phoneNumbers.first?.value.stringValue != nil{
//@TODO: check for repeats in people array
// do something with contact
let newPerson = Person(firstName: contact.givenName,
lastName: contact.familyName,
profileImage: #imageLiteral(resourceName: "capitalizing_on_the_economic_potential_of_foreign_entrepreneurs_feature.png"))
if contact.imageDataAvailable == true{
newPerson.profileImage = UIImage(data: contact.imageData!)!
}
// this is for the full name
let fullname = "\(contact.givenName) \(contact.familyName)"
print("The selected name is: \(fullname)")
let phoneNum = contact.phoneNumbers.first?.value.stringValue
print("The selected phone num is: \(phoneNum!)")
//appends data to new activity model for prep to send back to home vc
newActivity.people.append(newPerson)
print("the people in the new activity array are: \(newActivity.people)")
peopleCollection.reloadData()
} else {
print("error has no number")
let alertController = UIAlertController(title: "Error: Person has no number!", message: "", preferredStyle: .alert)
let confirmAction = UIAlertAction(title: "Ok", style: .default, handler: {
alert -> Void in
})
//add actions to alert sheet
alertController.addAction(confirmAction)
self.present(alertController, animated: true, completion: nil)
//the code executes here correctly, but it does not present the alertController
}
//this is for phone number without dashes
//print("the selected phone number is: \((contact.phoneNumbers[0].value).value(forKey: "digits") as! String)")
}
編集:最後のコメントアウトされていない行はpicker.present(alertController、animated:true、completion:nil)である必要があります。しかし、今、別の問題があります。アラートビューは、ユーザーが[OK]をクリックするのを待つことなく、単独で消えます。それは約1秒間ポップアップされたままです。ユーザーが[OK]をクリックするまで、どのようにポップアップ表示されるようにするには? –