2017-10-02 18 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

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


}