I'm trying to develop an iPhone app and implementing on it a functionality similar to snapchat's and so many other apps: i want to ask for the user's mobile phone number and add it to my database. I then want to ask for permission to access my address book and based on my mobile phone contacts (friends mobile number) i can suggest the profiles of my friends who have installed the app. I developed some functions in which I was able to get all the user's contacts as a string. But i have some issues. People can write the mobile numbers in different ways (putting the country code in first place, etc). Since i am matching an exact string it becomes kind of hard.
Is there any solution for this problem? I know that different countries have different ways of writing the mobile numbers. F.e. in Portugal we can write 00351 911 111 111 or +351 911 111 111 or 911 111 111 . This will be easy to solve in portugal since we all have the last 9 digits and it is easy to compare. But in the US i have seen (555) XXX-XXXX or XXX-XXX-XXXX and many other formats.. I can't determine how the user has saved the contact and the same with other countries.
ALL HAPPENS AFTER ASKING FOR AN AUTHORIZATION
In the viewDidLoad i search in Parse the users of my mobile phone
Is there any solution for this problem? I know that different countries have different ways of writing the mobile numbers. F.e. in Portugal we can write 00351 911 111 111 or +351 911 111 111 or 911 111 111 . This will be easy to solve in portugal since we all have the last 9 digits and it is easy to compare. But in the US i have seen (555) XXX-XXXX or XXX-XXX-XXXX and many other formats.. I can't determine how the user has saved the contact and the same with other countries.
ALL HAPPENS AFTER ASKING FOR AN AUTHORIZATION
In the viewDidLoad i search in Parse the users of my mobile phone
Code:
override func viewDidAppear(animated: Bool) {
var query = PFUser.query()
query?.findObjectsInBackgroundWithBlock({ (objects, error) -> Void in
if let users = objects {
self.contactsUsernameArray.removeAll(keepCapacity: false)
self.contactsNameArray.removeAll(keepCapacity: false)
self.contactsImageFiles.removeAll(keepCapacity: false)
self.contactsNumberArray.removeAll(keepCapacity: false)
for object in users {
for var i = 0; i < self.phoneNumbers.count - 1; i++ {
if object["phoneNumber"] as! String == self.phoneNumbers[i] {
self.contactsUsernameArray.append(object.username!!)
self.contactsNameArray.append(object["name"] as! String)
self.contactsNumberArray.append(object["phoneNumber"] as! String)
self.contactsImageFiles.append(object["photo"] as! PFFile)
}
}
}
}
self.contactsTable.reloadData()
})
}