What's the issue:
Right now the contacts that are fetched might have a country code extension, for eg. it's 91 assuming it's an Indian contact. The problem arises when there's someone with a 0 as a country code or maybe even no country code. How do you match this with a database which has let's say all mobile number's with a +91 country code?
So, is there a way to clean up all the contacts? I'm not sure how much of this is possible with numbers from multiple countries and so on.
Let's consider this scenario:
Number fetched from the contacts - 9999999999 with no country code
Number which is saved in the database - 9999999999 with a country code 91
In such a scenario if the backend tries matching both these numbers, there won't be a match.
Code:
var store = CNContactStore()
do {
try store.enumerateContacts(with: CNContactFetchRequest(keysToFetch: [CNContactGivenNameKey as CNKeyDescriptor, CNContactFamilyNameKey as CNKeyDescriptor,CNContactPhoneNumbersKey as CNKeyDescriptor])) {(contact, cursor) -> Void in
for i in 0..<contact.phoneNumbers.count {
print((contact.phoneNumbers[i].value).stringValue)
}
}
}
catch {
print("Error")
}