Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I am working on a social network. I need to add a "find-friends" feature based on users' phone number and their address book (like whatsapp and others).

The app I am developing will be available globally and I was wondering how others deal with the problem of predials and country codes. Of course I could find a way around but I am sure this is a relatively common challenge associated with that feature. The problem is, some people save numbers with a country code and some people don't. Do i need two versions of a phone number in my database?

What I think about doing:

1) user registers with the number and types in the 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 another with the number excluding the country code.

2) Then another user looks for friends via its address book. In the PHP, each number is checked and the ones that start with "00" are compared against the numbers in the column of the international numbers. Vice versa, the ones that don't start with "00" are compared against the number without the country code. This way users can find their friends irrespective of how they saved their number.

I would appreciate any help, links, advice or direction. I am looking for best practice approaches.

Thanks!

like image 546
user3137177 Avatar asked Jun 20 '14 14:06

user3137177


People also ask

How do I automatically add country code to contacts?

Select the dialing options button, and another dialogue box will appear. Kindly check the Automatically add country/region code. Once you check the automatically add country/region code to local phone numbers, click okay and try to add a new contact and see if the code will be automatically added.

How do I use a code from another country?

Make an international call: First you dial the prefix-number (for most countries 00) + then the calling code number for the country + the area code (the city or region (for landlines only)) + last not least: the user number.


1 Answers

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

And then search friends by international phone number.

Example of usage:

        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];
        }
like image 54
Antigp Avatar answered Nov 15 '22 05:11

Antigp