GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - fred30/libPhoneNumber-iOS: iOS port from libphonenumber (Google's phone number handling library)

BranchesTags
Open more actions menu
 
 

Latest commit

 

History

64 Commits
64 Commits

Folders and files

NameName
Last commit message
Last commit date
libPhoneNumber.xcodeproj
libPhoneNumber.xcodeproj
 
 
libPhoneNumber
libPhoneNumber
 
 
libPhoneNumberTests
libPhoneNumberTests
 
 
.gitignore
.gitignore
 
 
.travis.yml
.travis.yml
 
 
AUTHORS
AUTHORS
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
libPhoneNumber-iOS.podspec
libPhoneNumber-iOS.podspec
 
 

Repository files navigation

libPhoneNumber for iOS

  • NBPhoneNumberUtil
  • NBAsYouTypeFormatter

ARC only, or add the "-fobjc-arc" flag for non-ARC

Using CocoaPods

pod 'libPhoneNumber-iOS', '~> 0.7'

Setting up Manually

Add source files to your projects from libPhoneNumber
- NBPhoneNumberUtil.h, .m
- NBAsYouTypeFormatter.h, .m

- NBNumberFormat.h, .m
- NBPhoneNumber.h, .m
- NBPhoneNumberDesc.h, .m
- NBPhoneNumberDefines.h
- NBPhoneMetaData.h, .m

- NSArray+NBAdditions.h, .m

- Add "NBPhoneNumberMetadata.plist" and "NBPhoneNumberMetadataForTesting.plist" to bundle resources
- Add "CoreTelephony.framework"

See sample test code from

libPhoneNumber-iOS/libPhoneNumberTests/libPhoneNumberTests.m

Usage - NBPhoneNumberUtil

    NBPhoneNumberUtil *phoneUtil = [NBPhoneNumberUtil sharedInstance];
    
    NSError *aError = nil;
    NBPhoneNumber *myNumber = [phoneUtil parse:@"6766077303"
                                 defaultRegion:@"AT" error:&aError];
    
    if (aError == nil) {
        // Should check error
        NSLog(@"isValidPhoneNumber ? [%@]", [phoneUtil isValidNumber:myNumber] ? @"YES":@"NO");
        
        // E164          : +436766077303
        NSLog(@"E164          : %@", [phoneUtil format:myNumber
                                          numberFormat:NBEPhoneNumberFormatE164
                                                 error:&aError]);
        // INTERNATIONAL : +43 676 6077303
        NSLog(@"INTERNATIONAL : %@", [phoneUtil format:myNumber
                                          numberFormat:NBEPhoneNumberFormatINTERNATIONAL
                                                 error:&aError]);
        // NATIONAL      : 0676 6077303
        NSLog(@"NATIONAL      : %@", [phoneUtil format:myNumber
                                          numberFormat:NBEPhoneNumberFormatNATIONAL
                                                 error:&aError]);
        // RFC3966       : tel:+43-676-6077303
        NSLog(@"RFC3966       : %@", [phoneUtil format:myNumber
                                          numberFormat:NBEPhoneNumberFormatRFC3966
                                                 error:&aError]);
    } else {
        NSLog(@"Error : %@", [aError localizedDescription]);
    }
    
    NSLog (@"extractCountryCode [%@]", [phoneUtil extractCountryCode:@"823213123123" nationalNumber:nil]);
    
    NSString *nationalNumber = nil;
    NSNumber *countryCode = [phoneUtil extractCountryCode:@"823213123123" nationalNumber:&nationalNumber];
    
    NSLog (@"extractCountryCode [%@] [%@]", countryCode, nationalNumber);
Output
2014-07-06 12:39:37.240 libPhoneNumberTest[1581:60b] isValidPhoneNumber ? [YES]
2014-07-06 12:39:37.242 libPhoneNumberTest[1581:60b] E164          : +436766077303
2014-07-06 12:39:37.243 libPhoneNumberTest[1581:60b] INTERNATIONAL : +43 676 6077303
2014-07-06 12:39:37.243 libPhoneNumberTest[1581:60b] NATIONAL      : 0676 6077303
2014-07-06 12:39:37.244 libPhoneNumberTest[1581:60b] RFC3966       : tel:+43-676-6077303
2014-07-06 12:39:37.244 libPhoneNumberTest[1581:60b] extractCountryCode [82]
2014-07-06 12:39:37.245 libPhoneNumberTest[1581:60b] extractCountryCode [82] [3213123123]

Usage - NBAsYouTypeFormatter

    NBAsYouTypeFormatter *f = [[NBAsYouTypeFormatter alloc] initWithRegionCode:@"US"];
    NSLog(@"%@", [f inputDigit:@"6"]); // "6"
    NSLog(@"%@", [f inputDigit:@"5"]); // "65"
    NSLog(@"%@", [f inputDigit:@"0"]); // "650"
    NSLog(@"%@", [f inputDigit:@"2"]); // "650 2"
    NSLog(@"%@", [f inputDigit:@"5"]); // "650 25"
    NSLog(@"%@", [f inputDigit:@"3"]); // "650 253"
    
    // Note this is how a US local number (without area code) should be formatted.
    NSLog(@"%@", [f inputDigit:@"2"]); // "650 2532"
    NSLog(@"%@", [f inputDigit:@"2"]); // "650 253 22"
    NSLog(@"%@", [f inputDigit:@"2"]); // "650 253 222"
    NSLog(@"%@", [f inputDigit:@"2"]); // "650 253 2222"
    // Can remove last digit
    NSLog(@"%@", [f removeLastDigit]); // "650 253 222"
Visit libphonenumber for more information or mail ([email protected])
Metadata managing (updating metadata)
Step1. Fetch "metadata.js" and "metadatafortesting.js" from Repositories
svn checkout http://libphonenumber.googlecode.com/svn/trunk/ libphonenumber-read-only
Step2. Convert Javascript Object to JSON using PHP scripts
Output - "PhoneNumberMetaData.json" and "PhoneNumberMetaDataForTesting.json"
Step3. Generate binary file from NBPhoneMetaDataGenerator
Output - "NBPhoneNumberMetadata.plist" and "NBPhoneNumberMetadataForTesting.plist"
Step4. Update exists "NBPhoneNumberMetadata.plist" and "NBPhoneNumberMetadataForTesting.plist" files

About

iOS port from libphonenumber (Google's phone number handling library)

Resources

Readme
Apache-2.0 license
Activity

Stars

0 stars

Watchers

1 watching

Forks

0 forks
Report repository

Releases

Packages

Contributors

You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.