如何从应用程序拨打电话

时间:2011-10-19 08:42:41

标签: iphone call

我想在第一个按钮上按钮programmaticaly通过点击按钮显示我的客户电话号码,然后用户可以拨打电话。在我的tableview中,我粘贴了以下代码

    marker *aMarker = [[marker alloc] init];
    PhoneLabel = [[[UILabel alloc] initWithFrame:CGRectMake(10, 45, 30, 20)] autorelease];
    PhoneLabel.tag = kPhoneLabelTag;
    PhoneLabel.font = [UIFont systemFontOfSize:14];
    [cell.contentView addSubview:PhoneLabel];

            PhoneB = [UIButton buttonWithType:UIButtonTypeCustom];
        [PhoneB setTitle:aMarker.phone forState:UIControlStateNormal];
     PhoneB.frame = CGRectMake(15, 45, 200, 20);
    PhoneB.font = [UIFont systemFontOfSize:14];
    PhoneB.titleLabel.textColor = [UIColor blackColor];
    [cell.contentView addSubview:PhoneB];
    [cell addSubview:PhoneB]; 
    [GetDirectionB addTarget:self
                      action:@selector(phonecall:)
            forControlEvents:UIControlEventTouchUpInside];

phonelabel

                PhoneLabel.text = [NSString stringWithFormat:@"p:%@"];

并采取行动

    -(void) phonecall:(id)sender
 {
marker *aMarker = [[marker alloc] init];
   tel:aMarker.phone;
  }

实际应该应用什么逻辑,以便在点击电话号码按钮时,将调用相同的号码。我从网址

获取“aMarker.phone”

3 个答案:

答案 0 :(得分:2)

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel://your number"]];

答案 1 :(得分:0)

您可以使用以下代码拨打电话。

-(void) phonecall:(id)sender
{
    NSString *number = @"123456..." // a phone nuber
    NSURL *phoneNumberURL = [NSURL URLWithString:[NSString stringWithFormat:@"tel://%@",number]];

    [[UIApplication sharedApplication] openURL:phoneNumberURL];
}

答案 2 :(得分:0)

以下代码有助于拨打写入标签的电话

if(![[UIDevice currentDevice].model isEqualToString:@"iPhone"])
        {
        UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:_ALERT_TITLE_MSG
                                                            message:@"This Phone is not support call facility"
                                                           delegate:self 
                                                  cancelButtonTitle:@"Ok"
                                                  otherButtonTitles: nil];
        [alertView show];
        [alertView release];
        }else {
            if([lblTel.text length]>0)
                [[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"tel://%@",lblTel.text,nil]]];
            else
                btnCallTapped.hidden=YES;

        }

希望这段代码能为您提供帮助。