2011-07-09 6 views
1
enter code here-(IBAction)Call:(id)sender{ 
//[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel://18005551234"]]; 
/*NSString *phoneStr = [[NSString alloc] initWithFormat:@"tel:%@",phoneNumber.text]; 
NSURL *phoneURL = [[NSURL alloc] initWithString:phoneStr]; 
[[UIApplication sharedApplication] openURL:phoneURL]; 
[phoneURL release]; 
[phoneStr release];*/ 
NSURL *url = [ [ NSURL alloc ] initWithString: @"tel:212-555-1234" ]; 
[[UIApplication sharedApplication] openURL:url]; 

}上記のコードでは ですが、私はいろいろな方法を使っていますが、誰も働いていません。関数上でブレークポイントを実装すると、スコープ外であると言います。これの問題は何ですか?ボタンを押すと、通話/ダイヤルの数値表示が開きます。

答えて

2

電話番号からハイフン「 - 」と括弧「(」、「)」を削除する必要があります。数字以外には特殊文字はありません。

NSCharacterSet *specialCharSet = [NSCharacterSet characterSetWithCharactersInString:@")(-,"]; 
NSArray *components = [phoneNumber.text componentsSeparatedByCharactersInSet:specialCharSet]; 
NSString *phoneStr = [components componentsJoinedByString:@""]; 
phoneStr = [NSString stringWithFormat:@"tel:%@", phoneStr]; 
NSURL *url = [[NSURL alloc] initWithString:phoneStr]; 
[[UIApplication sharedApplication] openURL:url]; 
+0

どちらが正しいですか? – ram

+0

必要に応じて任意の方法を使用できます。携帯電話番号が動的な場合は、別の変数に保持して* stringWithFormat:*メソッドを使用して追加することができます。 – EmptyStack

+0

どちらが良いですか?シミュレータでは、いずれかのwork.pleaseは、使用されているコード行を記述します。 – ram

関連する問題