Dial a phone number with an access code programmatically in iOS

前端 未结 10 1107
既然无缘
既然无缘 2020-12-02 06:54

How can I dial a phone number that includes a number and access code programmatically in iOS?

For example:

number: 900-3440-567
Access C

相关标签:
10条回答
  • 2020-12-02 07:08

    There are a number of ways to dial a phone number and the way described that uses:

    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel:555-555-5555"]

    Is a valid way to do this however it has a number of issues. First it doesn't properly prompt the user and secondly it doesn't bring the user back to the application when the phone call is completed. To properly place a phone call you should both prompt before the call so you don't surprise the user and you should bring the user back to the application once the call is done.

    Both of these can be accomplished without using a private API as is suggested by some of the answers here. The recommended approach uses the telprompt api but it doesn't use the private instantiation of the call and instead creates a web view allowing for future compatibility.

    + (void)callWithString:(NSString *)phoneString
    {
        [self callWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"tel:%@",phoneString]]];
    }
    + (void)callWithURL:(NSURL *)url
    {
        static UIWebView *webView = nil;
        static dispatch_once_t onceToken;
        dispatch_once(&onceToken, ^{  
            webView = [UIWebView new];
        });
        [webView loadRequest:[NSURLRequest requestWithURL:url]];
    }
    

    A sample project and additional information is provided here: http://www.raizlabs.com/dev/2014/04/getting-the-best-behavior-from-phone-call-requests-using-tel-in-an-ios-app/

    0 讨论(0)
  • 2020-12-02 07:11

    I don't know if you actually found a solution for passing the access code, but for me this code worked:

    NSString *dialstring = [[NSString alloc] initWithFormat:@"tel:your_phonenumber,your_accessnumber"]; 
    

    That will result in a dial string with the following values: tel:9003440567,65445

    The remaining parts are managed by the phone app of iOS with the following command:

    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:dialstring]];
    

    The , in the string causes a pause in your telephonesystem (the one where you want to access a conference room) right after the first number is dialed and a connection is established. So the telephonesystem has time to ask you for the access code (I think it should ask you, that's the way our system works). And after that your access code should be passed.

    BE AWARE: Your access code will be passed in in a non-secret way. For example: Your shown access code will be displayed in the iPhone phone app display this way: 9003440567, 65445

    0 讨论(0)
  • 2020-12-02 07:12

    Here is a self-contained solution in Swift:

    private func callNumber(phoneNumber:String) {
      if let phoneCallURL:NSURL = NSURL(string: "tel://\(phoneNumber)") {
        let application:UIApplication = UIApplication.sharedApplication()
        if (application.canOpenURL(phoneCallURL)) {
          application.openURL(phoneCallURL);
        }
      }
    }
    

    Now you should be able to use callNumber("7178881234") to make a call; hope this helps!

    0 讨论(0)
  • 2020-12-02 07:20

    You can use Phone urls to invoke the Phone application to dial a number for you. See this reference.

    The downside is that once the call is finished, user will endup in the Phone application. But I am afraid there is no solution to that problem. iOS doesn't allow any application to directly initiate a call because of security and privacy reasons.

    You can use comma for introducing pause(s) while dialing a number.

    0 讨论(0)
提交回复
热议问题