【问题标题】:I want to call phone number "#51234" in Xcode use telprompt [duplicate]我想在 Xcode 中使用 telprompt 拨打电话号码“#51234”[重复]
【发布时间】:2013-09-06 00:41:05
【问题描述】:

我想在 Xcode 中使用 telprompt 拨打电话号码“#51234”。

但 telprompt 拒绝它。

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

nzomeNum 是“1234”

【问题讨论】:

    标签: ios phone-call hashtag telprompt


    【解决方案1】:

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

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

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

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

    【讨论】:

    【解决方案2】:

    很遗憾,您无法拨打任何号码,包括主题标签。 Apple 明确限制了这些调用:iPhoneURLScheme_Reference

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-06-17
      • 2013-02-07
      • 1970-01-01
      • 2021-07-15
      • 1970-01-01
      • 2023-03-26
      • 1970-01-01
      • 2018-03-09
      相关资源
      最近更新 更多