2017-10-02 2 views
-1

Ich habe den folgenden Code, um Anrufe aus der App zu tätigen. Wenn ich jedoch auf den Knopf klicke, passiert nichts. Irgendwelche Gedanken, was ich falsch machen könnte?Taste zum Telefonieren in iOS Xcode

- (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"); 
     } 
    }]; 
} 
+1

Niemand weiß, was dictArray ist. –

+0

Duplizieren: https://stackoverflow.com/questions/27259824/calling-a-phone-number-in-swift –

+0

können Sie uns Ihr dictArray ?? – luckyShubhra

Antwort

0

Versuchen Sie dies und sehen (Clear Ihr Konsolenprotokoll vor Ihrer Pressetelefontaste. Lassen Sie mich wissen, was macht Ihre Schaltfläche Aktion Druck)

- (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"); 
    } 


}