在iOS应用程序中拨打电话
我有一些代码试图在应用程序中进行调用,但似乎没有工作:
UIApplication *myApp = [UIApplication sharedApplication]; NSString *theCall = [NSString stringWithFormat:@"tel://%@",phone]; NSLog(@"making call with %@",theCall); [myApp openURL:[NSURL URLWithString:theCall]];  有时,可变phone是诸如@"(102) 222-2222" 。 如何用这样的电话号码拨打电话? 我是否需要手动提取数字,摆脱所有额外的标点符号? 
对。 你需要把这些拿出来。 或者你可以使用下面的代码片段…
 NSString *cleanedString = [[phoneNumber componentsSeparatedByCharactersInSet:[[NSCharacterSet characterSetWithCharactersInString:@"0123456789-+()"] invertedSet]] componentsJoinedByString:@""]; NSURL *telURL = [NSURL URLWithString:[NSString stringWithFormat:@"tel:%@", cleanedString]]; 
 注意:你可能会试图使用-stringByTrimmingCharactersInSet: ,但是只能删除string开头和结尾的字符,而不是在中间出现。 
要回到原来的应用程序,您可以使用telprompt://而不是电话:// – 告诉提示将首先提示用户,但是当通话结束后,它将返回到您的应用程序:
 NSString *phoneNumber = [@"telprompt://" stringByAppendingString:mymobileNO.titleLabel.text]; [[UIApplication sharedApplication] openURL:[NSURL URLWithString:phoneNumber]]; 
只是上面的答案更新。
这是一个简单的方法,可以用来打电话,并在通话结束后返回到应用程序。
将以下内容添加到.m文件
 - (void) dialNumber:(NSString*) number{ number = [@"telprompt://" stringByAppendingString:number]; [[UIApplication sharedApplication] openURL:[NSURL URLWithString:number]]; } 
然后添加下面的代码,无论你想打电话从:
 [self dialNumber:@"5031234567"];