现在只是用你的代码替换此代码,可能是其发生是因为在PHONENO或电话网址空白的地方用所以它不是called..use这个代码..
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];
}
UPDATE:
尝试,这也...
#import "RegexKitLite.h"
NSString * number = @"(555) 555-555 Office";
NSString * strippedNumber = [number stringByReplacingOccurrencesOfRegex:@"[^0-9]" withString:@""];
看到链接此代码iphone sdk - Remove all characters except for numbers 0-9 from a string
请的NSLog THR phoneURLString并检查它是否正确与否 –