Navnath Memane
Navnath Memane

Reputation: 273

How to make call from application

I want to take button programmaticaly on first button my customer phone number will be display by tapping on the button then the user can call. In my tableview I have pasted following code

    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 is

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

And on action

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

actually what logic should I applied so that when tapping the phone number button the same number will be called. I am fetching "aMarker.phone" from the URL

Upvotes: 0

Views: 285

Answers (3)

Nimit Parekh
Nimit Parekh

Reputation: 16864

Following code is help for the call the phone which is written into label

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;

        }

Hope this code helping to you.

Upvotes: 0

Volodymyr B.
Volodymyr B.

Reputation: 3441

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

Upvotes: 2

Maulik
Maulik

Reputation: 19418

you can use below code to make a call.

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

    [[UIApplication sharedApplication] openURL:phoneNumberURL];
}

Upvotes: 0

Related Questions