Making a phone call in an iOS application

Yup. You need to take those out yourself. Or you can use the snippet below…

NSString *cleanedString = [[phoneNumber componentsSeparatedByCharactersInSet:[[NSCharacterSet characterSetWithCharactersInString:@"0123456789-+()"] invertedSet]] componentsJoinedByString:@""];
NSURL *telURL = [NSURL URLWithString:[NSString stringWithFormat:@"tel:%@", cleanedString]];

Note: you may be tempted to use -stringByTrimmingCharactersInSet:, but that one only removes characters at the start and the end of the string, not if they appear in the middle.

Leave a Comment