Question

Is a telephone number with "+" different from one without "+"?

I mean that a number such as A: +1(510)234-567 and B:1510234567. Is it the same number for the call? I want to make a call which number to get from the address book. The format is A, and after use,

NSCharacterSet *doNotWant = [NSCharacterSet characterSetWithCharactersInString:@"-+() *#"];
txt = [[txt componentsSeparatedByCharactersInSet: doNotWant] componentsJoinedByString: @""];

the number format is B.

Is it a good solution?

Was it helpful?

Solution

The following code may help you solve the problem! Have a try.

- (NSURL *)makeCall:(NSString *)number
{
    NSString *txt = number;
    NSString *cleanedString = [[txt componentsSeparatedByCharactersInSet:[[NSCharacterSet characterSetWithCharactersInString:@"0123456789-+()"] invertedSet]] componentsJoinedByString:@""];
    NSURL *telURL = [NSURL URLWithString:[NSString stringWithFormat:@"tel:%@", cleanedString]];
    return telURL;
}

BOOL bCanCall = [[UIApplication sharedApplication]canOpenURL:urlToCall];

if (bCanCall)
{
    UIWebView *callView = [[[UIWebView alloc]init] autorelease];
    [callView loadRequest:[NSURLRequest requestWithURL:urlToCall]];
    [self.view addSubview:callView];
}

OTHER TIPS

From the Wikipedia article Telephone numbering plan, Country code:

Country code - necessary only when dialing to phones in other countries. In international usage, telephone numbers are prefixed with the country code preceded by a "+", and with spaces in place of hyphens (e.g., "+XX YYY ZZZ ZZZZ"). This allows the reader to choose which Access Code (also known as International Dialing Digit) they need to dial from their location. However, it is often quoted together with the international access code which must precede it in the dial string, for example "011" in NANP countries (including Canada, Bermuda, and the United States): "011-XX-YYY-ZZZ-ZZZZ", or "00" in most European countries: "00-XX-YYY-ZZZ-ZZZZ". This can cause confusion as a different Access Code may be used where the reader is located. On GSM networks, "+" is an actual character that may be used internally as the international access code, rather than simply being a convention.

It looks like + is not mandatory, but it makes it clear if someone is dialing international areas.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top