Issue
I am using this code for getting contact number from contacts app but when I want to show the number in label I get this warning and doesn't work: Cast from 'CNPhoneNumber' to unrelated type 'String' always fails
func contactPicker(_ picker: CNContactPickerViewController, didSelect contacts: [CNContact]) {
contacts.forEach {(contact) in
for number in contact.phoneNumbers{
let phone = number.value
print(phone)
numberLabel.text = phone as! String
}
}
}
Solution
TRY :
if let phone = number.value as? CNPhoneNumber {
print(phone.stringValue)
} else {
print("number.value not of type CNPhoneNumber")
}
also take a look at CNContact , CNPhoneNumber
Answered By - PhillipJacobs Answer Checked By - David Marino (PHPFixing Volunteer)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.