IOS で、アドレス帳から取得した +-#*() を削除する方法。例えば:
NSString *txt = @"+1(510)1234567"
txt = [NSString stringWithFormat:@"tel://%@", txt];
[[UIApplication sharedApplication]canOpenURL:[NSURL URLWithString:txt]];
電話をかけるには無効な番号です。
[[UIApplication sharedApplication]openURL:[NSURL URLWithString:urlToCall]];
このタイプ番号には役に立ちません。
...を使用する以外に、いくつかのより良いオプションがありますか
[txt stringByReplacingOccurrencesOfString:@"-" withString:@""]
? 電話をかけたいだけです。
ご協力いただきありがとうございます。
実際、openURL で呼び出すことができます。呼び出しの形式は「tel://」ではなく、「tel:」です。だから、私がすべきことは次のとおりです。
NSString *cleanedString = [[phoneNumber componentsSeparatedByCharactersInSet:
[[NSCharacterSet characterSetWithCharactersInString:@"0123456789-+()"]
invertedSet]] componentsJoinedByString:@""];
NSURL *telURL = [NSURL URLWithString:[NSString stringWithFormat:@"tel:%@", cleanedString]];
それで大丈夫です。
——————————————————————————————— @"tel://" は電話をかける正しい URL ではありません。 @"tel:" を使用する必要があります。
+1 (510) 3436 などの数値でない場合は、
BOOL bCanCall = [[UIApplication sharedApplication]canOpenURL:urlToCall]; False を返します。電話をかけることはできません。