现在只需用您的代码替换此代码,可能是因为在 phoneno 或 phone url 中使用了空格,所以它没有被调用..使用此代码..
NSString *phoneNumber = [[self.arrCategory objectAtIndex:0]objectForKey:@"MOBILE"];
NSArray* telComponents = [phoneNumber componentsSeparatedByCharactersInSet: [NSCharacterSet whitespaceAndNewlineCharacterSet]];
phoneNumber = [telComponents componentsJoinedByString: @""];
NSString* urlString = [NSString stringWithFormat: @"tel:%@", phoneNumber];
NSURL* telURL = [NSURL URLWithString: urlString];
if ( [[UIApplication sharedApplication] canOpenURL: telURL] )
{
[[UIApplication sharedApplication] openURL: telURL];
}
else
{
UIAlertView* alert = [[UIAlertView alloc] initWithTitle: NSLocalizedString( @"Dialer Error", @"" )
message: [NSString stringWithFormat: NSLocalizedString( @"There was a problem dialing %@.", @"" ), phoneNumber]
delegate: nil
cancelButtonTitle: NSLocalizedString( @"OK", @"" )
otherButtonTitles: nil];
[alert show];
[alert release];
}
更新:
试试这个也...
#import "RegexKitLite.h"
NSString * number = @"(555) 555-555 Office";
NSString * strippedNumber = [number stringByReplacingOccurrencesOfRegex:@"[^0-9]" withString:@""];
从 iphone sdk 查看此代码的链接 - 从字符串中删除除数字 0-9 之外的所有字符