【问题标题】:Make call from iphone application programmatically以编程方式从 iphone 应用程序拨打电话
【发布时间】: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


【解决方案1】:

您需要在 iPhone 上进行测试,因为您无法在 iOS 模拟器上拨打电话。您也无法在 iPod Touch 和 iPad 上拨打电话。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-10-29
    • 1970-01-01
    • 1970-01-01
    • 2012-04-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多