How can I make phone call in iOS?

后端 未结 8 2332
不思量自难忘°
不思量自难忘° 2020-12-07 23:05

How can I make a phone call in Objective-C?

相关标签:
8条回答
  • 2020-12-07 23:18
    NSString *phoneNumber = @"Phone number here";
    UIWebView *webView = [[UIWebView alloc] init];
    NSURL *url = [NSURL URLWithString:numberString];        
    NSURLRequest *requestURL = [NSURLRequest requestWithURL:url]; 
    webView.dataDetectorTypes = UIDataDetectorTypeNone;
    [webView loadRequest:requestURL];
    
    0 讨论(0)
  • 2020-12-07 23:19

    It may also be helpful to know how to prompt the user to call a number:

    NSURL *phoneNumber = [NSURL URLWithString:@"telprompt://13232222222"];
    [[UIApplication sharedApplication] openURL:phoneNumber];
    

    telprompt gives the user a choice to place the call or cancel making the call before the phone dials. The two forward slashes after the colon are optional.

    0 讨论(0)
  • 2020-12-07 23:19

    This will either be very platform-specific, or you'll have to use a wrapper library to account for the differences among platforms, so you better state what platform this is intended for. In general, there are various telephony APIs available on most platforms.

    On Windows systems there's for example the "TAPI", also things may somewhat differ if you are targeting a digital telephone system such as ISDN, because there are other APIs available.

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

    You can initiate a call

    https://developer.apple.com/library/archive/featuredarticles/iPhoneURLScheme_Reference/PhoneLinks/PhoneLinks.html

    So this would probably work:

    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel:12125551212"]];
    
    0 讨论(0)
  • 2020-12-07 23:25

    openURL is deprecated.

    Now use this:

    UIApplication *application = [UIApplication sharedApplication];
    [application openURL:[NSURL URLWithString: @"tel:12125551212"] options:@{} completionHandler:nil];
    
    0 讨论(0)
  • 2020-12-07 23:34

    REMOVE EMPTY SPACES IN PHONE NUMBER

    NSString *phoneNumberString = @"123 456";
    phoneNumberString = [phoneNumberString stringByReplacingOccurrencesOfString:@" " withString:@""];
    phoneNumberString = [NSString stringWithFormat@"tel:%@", phoneNumberString];
    NSURL *phoneNumberURL = [NSURL URLWithString:phoneNumberString]];
    [[UIApplication sharedApplication] openURL:phoneNumberURL];
    
    0 讨论(0)
提交回复
热议问题