2013-01-03 13 views
0

我已经完成了这样的编程调用。不能通过编程方式拨打iphone

NSString *phoneNumber = [[self.arrCategory objectAtIndex:0]objectForKey:@"MOBILE"]; 

NSString *phoneURLString = [NSString stringWithFormat:@"tel:%@", phoneNumber]; 
NSURL *phoneURL = [NSURL URLWithString:phoneURLString]; 
[[UIApplication sharedApplication] openURL:phoneURL]; 

但我不能从iphone进行呼叫。什么是问题?

+0

请的NSLog THR phoneURLString并检查它是否正确与否 –

回答

1

试试这个&检查:

NSString *phoneNumber = [[self.arrCategory objectAtIndex:0]objectForKey:@"MOBILE"]; 
    NSString *phoneURLString = [@"tel://" stringByAppendingString:phoneNumber]; 
    NSURL *phoneURL = [NSURL URLWithString:phoneURLString]; 
    [[UIApplication sharedApplication] openURL:phoneURL]; 
2

现在只是用你的代码替换此代码,可能是其发生是因为在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

+0

显示它像错误:[__ NSCFNumber componentsSeparatedByCharactersInSet:]:无法识别的选择发送到实例0x1f831cd0' ***第一掷调用堆栈: – jinal

+0

哎,你得到的错误? ?是指你得到它的哪一行? –

+0

这里NSArray * telComponents = [phoneNumber componentsSeparatedByCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]; – jinal

0

试试这个:

UIWebView *callWebview = [[UIWebView alloc] initWithFrame:CGRectMake(0,0, 0, 0)]; 
[self.view addSubview:callWebview]; 
NSString *phoneNumber = [[self.arrCategory objectAtIndex:0]objectForKey:@"MOBILE"]; 
    NSString *phoneWithoutSpaces = [[NSString stringWithFormat:@"tel://%@", phoneNumber] stringByReplacingOccurrencesOfString:@" " withString:@""]; 
NSURL *telURL = [NSURL URLWithString:phoneWithoutSpaces]; 
[callWebview loadRequest:[NSURLRequest requestWithURL:telURL]]; 

这是为我工作。

相关问题