Code Monkey home page Code Monkey logo

Comments (3)

iziz avatar iziz commented on August 29, 2024

Please show me your code sample.

from libphonenumber-ios.

wojciechczyz avatar wojciechczyz commented on August 29, 2024

Hi,

I am using this method and calling it providing non country marked number for example:
“123 123 123”

+(NSString *)NormalizePhoneNumber : (NSString *)AnyPhoneNumber
{
NSString *NormalizedPhoneNumber;
@Try
{
NBPhoneNumberUtil *phoneUtil = [[NBPhoneNumberUtil alloc] init];
NSError *anError = nil;
NBPhoneNumber *myNumber = [phoneUtil parseWithPhoneCarrierRegion:AnyPhoneNumber error:&anError];
if (anError == nil)
{
NormalizedPhoneNumber = [phoneUtil format:myNumber numberFormat:NBEPhoneNumberFormatE164 error:&anError];
if (anError == nil)
{
NSLog(@"E164 normalized: %@", NormalizedPhoneNumber);

        }
        else
        {
            NSLog(@"Failed normalizing: %@, Error: %@", AnyPhoneNumber, anError);
            [phoneUtil normalizePhoneNumber : AnyPhoneNumber];
        }
    }
    else
    {
        NSLog(@"Failed parsing: %@, Error: %@", AnyPhoneNumber, anError);
        NormalizedPhoneNumber = [phoneUtil normalizePhoneNumber : AnyPhoneNumber];
    }
}
@catch (NSException *CatchedException)
{
    NSLog(@"Failed parsing and normalizing phone:%@, Error:%@", AnyPhoneNumber, CatchedException.description);
    NormalizedPhoneNumber = AnyPhoneNumber;
}

return NormalizedPhoneNumber;

}

I can see that internally “es” is detected but it fails to convert it to +34.
Thanks,
Wojciech

On Mar 17, 2015, at 14:33, iziz [email protected] wrote:

Please show me your code sample.


Reply to this email directly or view it on GitHub #55 (comment).

from libphonenumber-ios.

iziz avatar iziz commented on August 29, 2024

"parseWithPhoneCarrierRegion" will works only real device because accessing device sim card.

In simulator... (defaultRegion "ZZ" -> "US")

NSLog(@"%@", [AppDelegate NormalizePhoneNumber:@"123 123 123"]);

shows

2015-03-18 15:43:13.690 PhoneNumberDevelopment[10350:264935] E164 normalized: +123123123
2015-03-18 15:43:13.691 PhoneNumberDevelopment[10350:264935] +123123123

but, can't find that error.

I tried

    NBPhoneNumberUtil *phoneUtil = [[NBPhoneNumberUtil alloc] init];
    NSError *error = nil;

    NBPhoneNumber *phoneNumber = [phoneUtil parse:@"123 123 123" defaultRegion:@"ES" error:&error];
    if (!error) {
        NSLog(@"%@", [phoneUtil format:phoneNumber numberFormat:NBEPhoneNumberFormatE164 error:&error]);
    }

and it's result

2015-03-18 15:48:12.079 PhoneNumberDevelopment[10443:268516] +34123123123

So, tell me your expected result.

from libphonenumber-ios.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.