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

1

8

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!

Griffin answered 20/6, 2014 at 14:47 Comment(0)
S
6

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];
        }
Sedulity answered 4/7, 2014 at 10:59 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.