2017-10-02 25 views
-1

アプリ内から電話をかけるには、次のコードがあります。しかし、ボタンをクリックするたびに何も起こりません。私が間違っているかもしれない考え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

誰もdictArrayが何であるかを知りません。 –

+0

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

+0

あなたのdictArrayを表示できますか? – luckyShubhra

答えて

0

(あなたのプレス携帯電話のボタンの前に、あなたのコンソールログをクリア。私はあなたのボタンアクション印刷を何知ってみましょう)、これを試してみてください

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


} 
関連する問題