-1

I have the following code to make phone calls from within the app. However, whenever I click on the button - nothing happens. Any thoughts what I might be doing wrong?

- (void)phonePressed:(id)sender
{
    UIButton *btn = (UIButton* )sender;
    NSString *key = [self.dictArray.allKeys objectAtIndex:btn.tag];
    NSMutableArray *arrData = [self.dictArray objectForKey:key];
    NSMutableDictionary *dict = [arrData objectAtIndex:btn.tag];

    UIApplication *application = [UIApplication sharedApplication];
    NSURL *URL = [NSURL URLWithString:[NSString stringWithFormat:@"tel://%@",[dict objectForKey:@"contact_phone"]]];
    [application openURL:URL options:@{} completionHandler:^(BOOL success) {
        if (success) {
            NSLog(@"Opened url");
        }
    }];
}
rmaddy
  • 314,917
  • 42
  • 532
  • 579
SamIAm
  • 51
  • 3

1 Answers1

0

Try this and See (Clear your console log before your press Phone button. Let me know what does your button action print)

- (void)phonePressed:(UIButton *)btn {

    NSLog(@"dictArray = %@", dictArray);
    if (self.dictArray == nil || self.dictArray.count == 0) {
      NSLog(@"There is not data/elements in self.dictArray");
    }

    NSDictionary *dict = [self.dictArray objectAtIndex:btn.tag];
    NSLog(@"dict = %@", dict);

    if (dict == nil || dict.count == 0) {
      NSLog(@"There is not data/elements in dict");
    }

    NSString * contact_phone = [dict objectForKey:@"contact_phone"]
    NSLog(@"contact_phone = %@", contact_phone);

    if (contact_phone == nil) {
      NSLog(@"There is not value for contact_phone");
    }

    NSURL *URL = [NSURL URLWithString:[NSString stringWithFormat: @"tel://%@", contact_phone]];

    NSLog(@"URL = %@", URL);

    if (URL == nil) {
      NSLog(@"URL is nil");
    }


    UIApplication *application = [UIApplication sharedApplication];

    if ([application canOpenURL: URL]) {
      [application openURL:URL options:@{} completionHandler:^(BOOL success) {
         if (success) {
          NSLog(@"Opened url");
         }
      }];
    } else {
       NSLog(@"Application cannot open URL");
    }


}
Krunal
  • 77,632
  • 48
  • 245
  • 261