In my application i am trying to format phone numbers based on the user locale. The issue i am facing is as follows:
Code in the Viewcontroller.m:
NSString *contact = [_phone convertContact:myNumber withLocale:typeN];
NSLog(@"Phone number %@ and number = %@",contact,myNumber);
//Console output 2012-07-23 15:40:16.994 InternProj[7585:f803] value of en and 23443235434
Code in the PhoneNumber.m:
- (NSString *) convertContact:(NSNumber *)aNumber withLocale:(NSString *)locale{
NSString *localeString = locale ;
NSLog(@"value of %@ and %@",localeString , aNumber);
NSString *tempStr = [[NSString alloc] initWithString:@""];
NSRange range;
range.length = 3;
range.location = 3;
//Returns the phone number 2032225200 as 1(203)222-5200
if([localeString compare:@"en"] == NSOrderedSame) {
NSLog(@"Inside en");
NSString *areaCode = [[aNumber stringValue] substringToIndex:3];
NSString *phone1 = [[aNumber stringValue] substringWithRange:range];
NSString *phone2 = [[aNumber stringValue] substringFromIndex:6];
tempStr = [NSString stringWithFormat:@"1(%@)%@-%@", areaCode, phone1, phone2];
NSLog(@"Value tempStr = %@",tempStr);
}
else {
tempStr = [[aNumber stringValue] substringToIndex:3];
}
return tempStr;
}
I am getting a null as a return value from convertContact method. I tried all the permutations but I am not getting whr im going wrong. Also if anyone has Iphone locale based phone number formatting info please share.
First of all iOS does not support for Phone number formatting. The developer has to write his own plugins. Also do mention what is typeN variable that you are passing in the method. Also check whether aNumber is not null. I am pretty sure that the number that you are passing in the method is the cause for null.