Как сделать звонок из приложения - PullRequest
0 голосов
/ 19 октября 2011

Я хочу, чтобы кнопка была нажата программно на первой кнопке. Мой телефонный номер клиента будет отображаться нажатием кнопки, после чего пользователь сможет позвонить. В мою таблицу я вставил следующий код

    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.text = [NSString stringWithFormat:@"p:%@"];

И в действии

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

на самом деле, какую логику я должен применить, чтобы при нажатии кнопки номера телефона вызывался тот же номер. Я получаю "aMarker.phone" с URL

Ответы [ 3 ]

2 голосов
/ 19 октября 2011
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel://your number"]];
0 голосов
/ 19 октября 2011

Следующий код является справкой для звонка по телефону, который записан на этикетке

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;

        }

Надеюсь, этот код поможет вам.

0 голосов
/ 19 октября 2011

Вы можете использовать код ниже, чтобы позвонить.

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

    [[UIApplication sharedApplication] openURL:phoneNumberURL];
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...