wireapp/libPhoneNumber-iOS

Name: libPhoneNumber-iOS

Owner: Wire Swiss GmbH

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

Forked from: iziz/libPhoneNumber-iOS

Created: 2016-07-14 14:37:59.0

Updated: 2017-10-19 12:28:09.0

Pushed: 2017-04-04 07:02:47.0

Homepage:

Size: 2634

Language: Objective-C

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

CocoaPods CocoaPods Travis Coveralls Carthage compatible

libPhoneNumber for iOS

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

Update Log

https://github.com/iziz/libPhoneNumber-iOS/wiki/Update-Log

Install
Using CocoaPods
ce 'https://github.com/CocoaPods/Specs.git'
'libPhoneNumber-iOS', '~> 0.8'
Using Carthage

Carthage is a decentralized dependency manager that automates the process of adding frameworks to your Cocoa application.

You can install Carthage with Homebrew using the following command:

ew update
ew install carthage

To integrate libPhoneNumber into your Xcode project using Carthage, specify it in your Cartfile:

ub "iziz/libPhoneNumber-iOS"

And set the Embedded Content Contains Swift to “Yes” in your build settings.

Setting up manually

Add source files to your projects from libPhoneNumber

- Add "CoreTelephony.framework"

See sample test code from

libPhoneNumber-iOS/libPhoneNumberTests/ … Test.m

Usage - NBPhoneNumberUtil
honeNumberUtil *phoneUtil = [[NBPhoneNumberUtil alloc] init];
rror *anError = nil;
honeNumber *myNumber = [phoneUtil parse:@"6766077303"
                          defaultRegion:@"AT" error:&anError];
(anError == nil) {
 NSLog(@"isValidPhoneNumber ? [%@]", [phoneUtil isValidNumber:myNumber] ? @"YES":@"NO");

 // E164          : +436766077303
 NSLog(@"E164          : %@", [phoneUtil format:myNumber
                                   numberFormat:NBEPhoneNumberFormatE164
                                          error:&anError]);
 // INTERNATIONAL : +43 676 6077303
 NSLog(@"INTERNATIONAL : %@", [phoneUtil format:myNumber
                                   numberFormat:NBEPhoneNumberFormatINTERNATIONAL
                                          error:&anError]);
 // NATIONAL      : 0676 6077303
 NSLog(@"NATIONAL      : %@", [phoneUtil format:myNumber
                                   numberFormat:NBEPhoneNumberFormatNATIONAL
                                          error:&anError]);
 // RFC3966       : tel:+43-676-6077303
 NSLog(@"RFC3966       : %@", [phoneUtil format:myNumber
                                   numberFormat:NBEPhoneNumberFormatRFC3966
                                          error:&anError]);
lse {
 NSLog(@"Error : %@", [anError localizedDescription]);


og (@"extractCountryCode [%@]", [phoneUtil extractCountryCode:@"823213123123" nationalNumber:nil]);

tring *nationalNumber = nil;
umber *countryCode = [phoneUtil extractCountryCode:@"823213123123" nationalNumber:&nationalNumber];

og (@"extractCountryCode [%@] [%@]", countryCode, nationalNumber);
Output
-07-06 12:39:37.240 libPhoneNumberTest[1581:60b] isValidPhoneNumber ? [YES]
-07-06 12:39:37.242 libPhoneNumberTest[1581:60b] E164          : +436766077303
-07-06 12:39:37.243 libPhoneNumberTest[1581:60b] INTERNATIONAL : +43 676 6077303
-07-06 12:39:37.243 libPhoneNumberTest[1581:60b] NATIONAL      : 0676 6077303
-07-06 12:39:37.244 libPhoneNumberTest[1581:60b] RFC3966       : tel:+43-676-6077303
-07-06 12:39:37.244 libPhoneNumberTest[1581:60b] extractCountryCode [82]
-07-06 12:39:37.245 libPhoneNumberTest[1581:60b] extractCountryCode [82] [3213123123]
with Swift Case (1) with Framework
rt libPhoneNumberiOS
Case (2) with Bridging-Header
anually added
ort "NBPhoneNumberUtil.h"
ort "NBPhoneNumber.h"

ocoaPods (check your library path)
ort "libPhoneNumber_iOS/NBPhoneNumberUtil.h"
ort "libPhoneNumber_iOS/NBPhoneNumber.h"

dd more if you want...
Case (3) with CocoaPods

import libPhoneNumberiOS

- in swift class file 2.x
ride func viewDidLoad() {
super.viewDidLoad()

let phoneUtil = NBPhoneNumberUtil()

do {
    let phoneNumber: NBPhoneNumber = try phoneUtil.parse("01065431234", defaultRegion: "KR")
    let formattedString: String = try phoneUtil.format(phoneNumber, numberFormat: .E164)

    NSLog("[%@]", formattedString)
}
catch let error as NSError {
    print(error.localizedDescription)
}

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"

NSLog(@"%@", [f inputString:@"16502532222"]); // 1 650 253 2222
Visit libphonenumber for more information or mail (zen.isis@gmail.com)

This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.