在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:iziz/libPhoneNumber-iOS开源软件地址:https://github.com/iziz/libPhoneNumber-iOS开源编程语言:Objective-C 52.1%开源软件介绍:libPhoneNumber for iOS
Update Loghttps://github.com/iziz/libPhoneNumber-iOS/wiki/Update-Log IssueYou can check phone number validation using below link. https://rawgit.com/googlei18n/libphonenumber/master/javascript/i18n/phonenumbers/demo-compiled.html Please report, if the above results are different from this iOS library. Otherwise, please create issue to following link below to request additional telephone numbers formatting rule. https://github.com/google/libphonenumber/issues Metadata in this library was generated from that. so, you should change it first. :) InstallCocoaPodsUsing
Installing libPhoneNumber Geocoding Features
CarthageUsingCarthage 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: $ brew update
$ brew install carthage To integrate libPhoneNumber into your Xcode project using Carthage, specify it in your
And set the Embedded Content Contains Swift to "Yes" in your build settings. Setting up manuallyAdd source files to your projects from libPhoneNumber - Add "CoreTelephony.framework" See sample test code from
Usage - NBPhoneNumberUtil NBPhoneNumberUtil *phoneUtil = [NBPhoneNumberUtil sharedInstance];
NSError *anError = nil;
NBPhoneNumber *myNumber = [phoneUtil parse:@"6766077303"
defaultRegion:@"AT" error:&anError];
if (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]);
} else {
NSLog(@"Error : %@", [anError localizedDescription]);
}
NSLog (@"extractCountryCode [%@]", [phoneUtil extractCountryCode:@"823213123123" nationalNumber:nil]);
NSString *nationalNumber = nil;
NSNumber *countryCode = [phoneUtil extractCountryCode:@"823213123123" nationalNumber:&nationalNumber];
NSLog (@"extractCountryCode [%@] [%@]", countryCode, nationalNumber); Output
with SwiftCase (1) with Framework
Case (2) with Bridging-Header// Manually added
#import "NBPhoneNumberUtil.h"
#import "NBPhoneNumber.h"
// CocoaPods (check your library path)
#import "libPhoneNumber_iOS/NBPhoneNumberUtil.h"
#import "libPhoneNumber_iOS/NBPhoneNumber.h"
// add more if you want... Case (3) with CocoaPodsimport libPhoneNumber_iOS - in swift class file2.xoverride func viewDidLoad() {
super.viewDidLoad()
guard let phoneUtil = NBPhoneNumberUtil.sharedInstance() else {
return
}
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 libPhoneNumberGeocodingFor more information on libPhoneNumberGeocoding and its usage, please visit libPhoneNumberGeocoding for more information. libPhoneNumberShortNumberFor more information on libPhoneNumberShortNumber and its usage, please visit libPhoneNumberShortNumber for more information. libphonenumber for more information or mail ([email protected])Visit |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论