【发布时间】:2014-10-01 14:50:36
【问题描述】:
我正在开发 iphone 应用程序并且我有带有电话号码的标签,我需要通过用户触摸电话号码拨打电话。我尝试使用以下代码但没有拨打电话,我目前正在使用 xcode 模拟器进行检查。
我的代码,
在我的头文件中
IBOutlet UILabel* lableMakeCall1;
@property(nonatomic,retain) UIView* lableMakeCall1;
我的 .m 文件包含
- (void)viewDidLoad
{
lableMakeCall1.userInteractionEnabled = YES;
UITapGestureRecognizer *tapGesture1 = \
[[UITapGestureRecognizer alloc]
initWithTarget:self action:@selector(didTapLabelWithGesture1:)];
[lableMakeCall1 addGestureRecognizer:tapGesture1];
}
- (void)didTapLabelWithGesture1:(UITapGestureRecognizer *)tapGesture1 {
NSString *phoneNumber = [@"tel://" stringByAppendingString:lableMakeCall1.text];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:phoneNumber]];
/*
I tried in this code also
NSString *phoneNumber = [@"telprompt://" stringByAppendingString:lableMakeCall1.text];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:phoneNumber]];*/
}
【问题讨论】:
-
另外,你使用
tel:<NUMBER>的spec says,即没有双斜杠,但你必须在手机上测试,或者如果你使用facetime:链接,那么你可以在安 ipod/ipad 上测试 -
还要确保电话号码中没有空格。
标签: ios ios-simulator call