iziz / libPhoneNumber-iOS

iOS port from libphonenumber (Google's phone number handling library)
Apache License 2.0
2.36k stars 465 forks source link

v1.0.2 not parsing phone number correctly #334

Open TripwireNL opened 3 years ago

TripwireNL commented 3 years ago

Hi,

I've been running into issues where phonenumbers aren't correctly parsed. It works on v0.9.15 but not on v1.0.2. I'm using this method:

+ (NSString *)getCountryFromCallee:(NSString *)locale PhoneNumber:(NSString *)phoneNumber {
  NBPhoneNumberUtil *phoneUtil = [NBPhoneNumberUtil new];
  NSError *error = nil;
  NBPhoneNumber *parsedNumber = [phoneUtil parse:phoneNumber defaultRegion:locale error:&error];

  if (error == nil && parsedNumber != nil) {
    return [phoneUtil getRegionCodeForNumber:parsedNumber];
  } else {
    DLog(@"Error parsing phone number: %@, Locale: %@ with error: %@ and parsedNumber: %@", phoneNumber, locale, error, parsedNumber);
    return @"";
  }
}

When parsing with a phonenumber like +31612345678 it returns the following error:

Error Domain=NOT_A_NUMBER Code=0 "Error Domain=NOT_A_NUMBER Code=0 "NOT_A_NUMBER:" UserInfo={NSLocalizedDescription=NOT_A_NUMBER:}" UserInfo={NSLocalizedDescription=Error Domain=NOT_A_NUMBER Code=0 "NOT_A_NUMBER:" UserInfo={NSLocalizedDescription=NOT_A_NUMBER:}}

However this works fine when using the online libphonenumber for testing.

mrpcalcantara commented 3 years ago

Check #324, you need to use the singleton instance.