iOS上带有主题标签的电话号码

时间:2012-10-27 06:10:19

标签: ios iphone phone-call

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

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

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

4 个答案:

答案 0 :(得分:5)

引用URL scheme docs

  

防止用户恶意重定向电话或更改   电话应用程序支持的电话或帐户的行为   tel方案中的大多数但不是全部的特殊字符。   具体来说,如果URL包含*或#字符,则为Phone   应用程序不会尝试拨打相应的电话号码。

从我所看到的情况看,它看起来像你可以使用的唯一方案是:

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel://1234567890p111"]];

拨打分机。

答案 1 :(得分:0)

*替换为%2A,将#替换为%23

NSURL *tel = [NSURL URLWithString:@"tel:%2A199%2A123456789%23"];
[[UIApplication sharedApplication] openURL:tel];

答案 2 :(得分:0)

根据我对现已结束的问题的回答重新发布和修改" iOS - I want to call phone number "#51234" in Xcode useing telprompt":

至少从iOS 11开始,一个可以拨打带有#标签(#)或星号(*)的数字。

首先使用这些字符进行调用编码电话号码,然后添加tel:前缀,最后将结果字符串转换为网址。

Swift 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") }
}

Objective-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"); }
                         }];

答案 3 :(得分:-1)

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