2012-04-05 9 views
0

私のアプリでは、選択した番号に電話をかけたいと思っています。このために、私はコードopenURLのtelが正しく機能しない

+(void)makeCallToSelectedContact:(NSString*)phoneNo{ 

    NSMutableString *phoneNumber = [NSMutableString stringWithString:phoneNo]; 

    [phoneNumber replaceOccurrencesOfString:@" " 
           withString:@"" 
            options:NSLiteralSearch 
             range:NSMakeRange(0, [phoneNumber length])]; 
    [phoneNumber replaceOccurrencesOfString:@"(" 
           withString:@"" 
            options:NSLiteralSearch 
             range:NSMakeRange(0, [phoneNumber length])]; 
    [phoneNumber replaceOccurrencesOfString:@")" 
           withString:@"" 
            options:NSLiteralSearch 
             range:NSMakeRange(0, [phoneNumber length])]; 

    NSLog(@"phoneNumber => %@",phoneNumber); 
    if([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:[NSString stringWithFormat:@"tel:+%@",phoneNumber]]]) { 
     [[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"tel:+%@",phoneNumber]]]; 
    } 
    else { 
     NSLog(@"Unable to open"); 
     [self showAlertWithTitle:@"Alert" andMessage:@"This Device Doesn't Support Call Functionality"]; 
    } 
} 

を以下している私は+91 1234567890のような無pHを持っている場合、それは正しく番号に電話しますと言うことができます。しかし、1234567890のような国番号+ &の国番号がない場合は、電話番号が+12 34567890に変換されています。ここに私のコンソールログです

2012-04-05 19:13:37.960 Search[22453:11003] phoneNumber => +911234567890 

2012-04-05 19:13:47.928 Search[22453:11003] phoneNumber => 1234567890 

私は行方不明ですか?どんな種類の助けにも感謝します。あなたはURLを作成するときに

答えて

1

あなたは '+' を追加している - 見て:

if([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:[NSString stringWithFormat:@"tel:+%@",phoneNumber]]]) { 
     [[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"tel:+%@",phoneNumber]]]; 
} 
関連する問題