0

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")
    }
Ameya Vichare
  • 1,119
  • 1
  • 10
  • 22
  • so you want phone number with country code from database...right? – Mahendra Jun 01 '18 at 10:39
  • No. I want to clean a number so that it could match with the database and there would be no such scenario where in a number is not matched just because of the country code. – Ameya Vichare Jun 02 '18 at 07:32

0 Answers0