1

Xcode で telprompt を使用して電話番号 "#51234" に電話をかけたいです。

しかし、telprompt はそれを拒否します。

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"telprompt://#5%@", nzoneNum]]];

nzomeNum は「1234」

4

2 に答える 2

3

少なくとも iOS 11 では、ハッシュタグ (#) またはアスタリスク (*) を使用して番号をダイヤルできます。

これらの文字を使用して電話をかけるには、最初に電話番号をエンコードしtel:、次にプレフィックスを追加し、最後に結果の文字列を URL に変換します。

スイフト 4、iOS 11

// set up the dial sequence
let nzoneNum = "1234"
let prefix = "#5"
let dialSequence = "\(prefix)\(nzoneNum)"

// "percent encode" the dial sequence with the URL Host allowed character set
guard let encodedDialSequence =
    dialSequence.addingPercentEncoding(withAllowedCharacters: .urlHostAllowed) else {
    print("Unable to encode the dial sequence.")
    return
}

// add the `tel:` url scheme to the front of the encoded string
let dialURLString = "tel:\(encodedDialSequence)"

// set up the URL with the scheme/encoded number string
guard let dialURL = URL(string: dialURLString) else {
    print("Couldn't make the dial string into an URL.")
    return
}

// dial the URL
UIApplication.shared.open(dialURL, options: [:]) { success in
    if success { print("SUCCESSFULLY OPENED DIAL URL") }
    else { print("COULDN'T OPEN DIAL URL") }
}

目的 C、iOS 11

// set up the dial sequence
NSString *nzoneNum = @"1234";
NSString *prefix = @"#5";
NSString *dialSequence = [NSString stringWithFormat:@"%@%@", prefix, nzoneNum];

// set up the URL Host allowed character set, and "percent encode" the dial sequence
NSCharacterSet *urlHostAllowed = [NSCharacterSet URLHostAllowedCharacterSet];
NSString *encodedDialSequence = [dialSequence stringByAddingPercentEncodingWithAllowedCharacters:urlHostAllowed];

// add the `tel` url scheme to the front of the encoded string
NSString *dialURLString = [NSString stringWithFormat:@"tel:%@", encodedDialSequence];

// set up the URL with the scheme/encoded number string
NSURL *dialURL = [NSURL URLWithString:dialURLString];

// set up an empty dictionary for the options parameter
NSDictionary *optionsDict = [[NSDictionary alloc] init];

// dial the URL
[[UIApplication sharedApplication] openURL:dialURL
                                   options:optionsDict
                         completionHandler:^(BOOL success) {
                             if (success) { NSLog(@"SUCCESSFULLY OPENED DIAL URL"); }
                             else { NSLog(@"COULDN'T OPEN DIAL URL"); }
                         }];
于 2017-12-30T21:58:45.167 に答える
2

残念ながら、ハッシュタグを含む任意の番号に電話をかけることはできません。Apple はこれらの呼び出しを明確に制限しています。

ユーザーが悪意を持って通話をリダイレクトしたり、電話やアカウントの動作を変更したりするのを防ぐために、電話アプリは tel スキームのほとんどの特殊文字をサポートしていますが、すべてではありません。具体的には、URL に * または # 文字が含まれている場合、電話アプリは対応する電話番号をダイヤルしようとしません。

于 2013-10-30T12:55:15.837 に答える