0
我正在开发iphone应用程序,我有标签的电话号码,我需要拨打电话号码从用户触摸。我尝试了下面的代码,但没有打电话,我目前正在使用xcode模拟器进行检查。通过编程从iphone应用程序拨打电话
我的代码,
在我的头文件
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]];*/
}
另外,[spec说](https://developer.apple.com/library/ios/featuredarticles/iPhoneURLScheme_Reference/PhoneLinks/PhoneLinks.html#//apple_ref/doc/uid/TP40007899-CH6-SW1)你使用'tel:',即没有双斜杠,但你必须在手机上测试,或者如果你使用'facetime:'链接,那么你可以测试ann ipod/ipad –
Petesh
2014-10-01 15:42:32
还要确保有电话号码中没有空格。 – rmaddy 2014-10-01 16:03:03