Phone number formatting is handled as part of address formatting, as the metadata for both types of formatting is in one common XML descriptor file.
// set default locale and country code [MAFAddressFormatter setDefaultLocale:@"hu"]; NSString* countryCode = @"hu";
Set a default locale as well, because if you do not set a value while formatting, you may get incorrect values.
You can use the phone number formatting capabilities of the MAFAddressFormatter in two ways:
In the first API call (formattedPhoneNumberWithCountryCode), obtain a full formatted string (NSString) that contains the properly formatted phone number with the proper extension suffix.
In the other API call (formattedLocalAndInternationalPhoneNumbersWithCountryCode), create and obtain a MAFPhoneNumber object. From that, you can obtain further types, such as local and international number formats of the input phone number value.
// A) specific phone number based formattings // EITHER get a full number in text NSString* formattedPhoneNumberText = [[MAFAddressFormatter instance] formattedPhoneNumberWithCountryCode:countryCode number:@"+36301234567" extension:@"321"]; NSLog(@"FORMATTED VALUE> %@", formattedPhoneNumberText);This code passes the numbers as an NString, in an international number format that is appropriate for the specified locale. It is important that you set the local or international number form (without any spaces or extra delimiters) specific to the locale or country code, because incorrect numbers are not formatted. You can provide the international number by using the + sign, or by using prefixing zeros (outbound number prefix).
The above code shows: FORMATTED VALUE> +36 30 123-4567 Ext. 321
// OR get a phone number object, that holds the various parts, and can be presented in more ways MAFPhoneNumber* formattedPhoneNumber = [[MAFAddressFormatter instance] formattedLocalAndInternationalPhoneNumbersWithCountryCode:countryCode number:@"+36301234567" extension:@"999"]; NSString* international = formattedPhoneNumber.internationalPhoneNumber; NSString* internationalWithOutbound = formattedPhoneNumber.internationalPhoneNumberWithCountryOutboundCode; NSString* local = formattedPhoneNumber.localPhoneNumber; NSLog(@"FORMATTED VALUE> %@", international); NSLog(@"FORMATTED VALUE> %@", internationalWithOutbound); NSLog(@"FORMATTED VALUE> %@", local);This code presents:
FORMATTED VALUE> +36 30 123-4567 Ext. 999
FORMATTED VALUE> 00 36 30 123-4567 Ext. 999
FORMATTED VALUE> 06 30 123-4567 Ext. 999
// B) country code based information NSString* outboundCode = [[MAFAddressFormatter instance] outboundCodeWithCountryCode:countryCode]; NSString* localTrunkPrefix = [[MAFAddressFormatter instance] localTrunkPrefixWithCountryCode:countryCode]; NSString* internationalDialCode = [[MAFAddressFormatter instance] internationalDialCodeWithCountryCode:countryCode]; NSLog(@"FORMATTED VALUE> %@", outboundCode); NSLog(@"FORMATTED VALUE> %@", localTrunkPrefix); NSLog(@"FORMATTED VALUE> %@", internationalDialCode);This code presents:
FORMATTED VALUE> 00
FORMATTED VALUE> 06
FORMATTED VALUE> +36
// set default locale and country code [MAFAddressFormatter setDefaultLocale:@"hu"]; NSString* countryCode = @"hu"; // A) specific phone number based formattings // EITHER get a full number in text NSString* formattedPhoneNumberText = [[MAFAddressFormatter instance] formattedPhoneNumberWithCountryCode:countryCode number:@"+36301234567" extension:@"321"]; NSLog(@"FORMATTED VALUE> %@", formattedPhoneNumberText); // OR get a phone number object, that holds the various parts, and can be presented in more ways MAFPhoneNumber* formattedPhoneNumber = [[MAFAddressFormatter instance] formattedLocalAndInternationalPhoneNumbersWithCountryCode:countryCode number:@"+36301234567" extension:@"999"]; NSString* international = formattedPhoneNumber.internationalPhoneNumber; NSString* internationalWithOutbound = formattedPhoneNumber.internationalPhoneNumberWithCountryOutboundCode; NSString* local = formattedPhoneNumber.localPhoneNumber; NSLog(@"FORMATTED VALUE> %@", international); NSLog(@"FORMATTED VALUE> %@", internationalWithOutbound); NSLog(@"FORMATTED VALUE> %@", local); // B) country code based information NSString* outboundCode = [[MAFAddressFormatter instance] outboundCodeWithCountryCode:countryCode]; NSString* localTrunkPrefix = [[MAFAddressFormatter instance] localTrunkPrefixWithCountryCode:countryCode]; NSString* internationalDialCode = [[MAFAddressFormatter instance] internationalDialCodeWithCountryCode:countryCode]; NSLog(@"FORMATTED VALUE> %@", outboundCode); NSLog(@"FORMATTED VALUE> %@", localTrunkPrefix); NSLog(@"FORMATTED VALUE> %@", internationalDialCode);