Application: use the address book to find friends: How to deal with country codes

I am working on a social network. I need to add the β€œfind friends” function based on the user's phone number and their address book (for example, whatsapp and others).

The application that I am developing will be available all over the world, and I was wondering how others deal with the problem of preliminary and country codes. Of course, I could find a way, but I am sure that this is a fairly common problem with this function. The problem is that some people store numbers with a country code, and some do not. Do I need two versions of a phone number in my database?

What I think about it:

1) user registers with numbers and types of country code, and the rest of the number separately (two text fields). Then there are two separate columns in the database. One with the whole number, including the country code, and the other with the number, except the country code.

2) Then another user searches for friends through his address book. In PHP, each number is checked, and those starting with "00" are compared with the numbers in the international number column. Conversely, those that do not start with β€œ00” are compared with a number without a country code. This way, users can find their friends no matter how they saved their number.

I would be grateful for any help, links, tips or guidance. I am looking for optimal approaches.

Thanks!

+7
ios server-side
source share
1 answer

You can format the local country phone number to an international phone number using this library libPhoneNumber . It uses big data format phones and country codes.

And then find friends by international phone number.

Usage example:

NSError* error = nil; //Parse local phone number using country code from CTCarrier NBPhoneNumber * phoneNumberObject = [[NBPhoneNumberUtil sharedInstance] parseWithPhoneCarrierRegion: phoneNumber error: &error]; if(error) { //This will get if no CTCarrier info. Maybe iPod, iPhone or iPad without sim error = nil; //You may put there another way to get user country code, or use default(Russia in example) phoneNumberObject = [[NBPhoneNumberUtil sharedInstance] parse: phoneNumber defaultRegion: @"RU" error: &error]; } NSString* formattedInternationalPhoneNumber; if(!error) { formattedInternationalPhoneNumber = [[NBPhoneNumberUtil sharedInstance] format: phoneNumberObject numberFormat: NBEPhoneNumberFormatE164 error: &error]; } 
+5
source share

All Articles