1

如何在 iOS 上拨打此号码 *199*123456789#?

我使用了以下代码,但它不起作用。

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel:*199*123456789#"]];
4

3 回答 3

1

从我对现已结束的问题“ iOS - 我想在 Xcode 中使用 telprompt 拨打电话号码“#51234”的回答中重新发布和修改:

至少从 iOS 11 开始,人们可以拨打带有井号 (#) 或星号 (*) 的号码。

通过首先对电话号码进行编码,然后添加tel:前缀,最后将生成的字符串转换为 URL来使用这些字符进行呼叫。

斯威夫特 4,iOS 11

// 1) set up the dial sequence as a String
let dialSequence = "*199*123456789#"

// 2) "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
}

// 3) add the `tel:` url scheme to the front of the encoded string
// NOTE: the '//' part is optional: either 'tel:' or 'tel://' will work.
let dialURLString = "tel:\(encodedDialSequence)"

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

// 5) 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

// 1) set up the dial sequence as a String
NSString *dialSequence = @"*199*123456789#";

// 2) "percent encode" the dial sequence with the "URL Host Allowed" character set
NSCharacterSet *urlHostAllowed = [NSCharacterSet URLHostAllowedCharacterSet];
NSString *encodedDialSequence = [dialSequence stringByAddingPercentEncodingWithAllowedCharacters:urlHostAllowed];

// 3) add the 'tel:' url scheme to the front of the encoded string
// NOTE: the '//' part is optional: either 'tel:' or 'tel://' will work.
NSString *dialURLString = [NSString stringWithFormat:@"tel:%@", encodedDialSequence];

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

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

// 6) 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"); }
                         }];
于 2018-06-18T16:40:55.743 回答
0

替换*%2A和:#_%23

NSURL *tel = [NSURL URLWithString:@"tel:%2A199%2A123456789%23"];
[[UIApplication sharedApplication] openURL:tel];
于 2018-06-18T09:22:06.333 回答
-1

您需要使用 tel:// 而不仅仅是 tel:

于 2012-10-27T06:12:54.780 回答