What’s the correct URL for placing a call on an iPhone?

前端 未结 5 892
闹比i
闹比i 2020-12-11 06:55

Is the code for calling on the iPhone automatically

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@\"tel:11111111111\"]]);
5条回答
  •  自闭症患者
    2020-12-11 07:28

    SwiftArchitect's answer doesn't fit all. I wanted to actually initiate an automatic call, not prompt.

    So there is a difference between tel and telprompt.

    tel: actually initiates the call.

    if let url = URL(string: "tel:\(phoneNumber)") {
      if UIApplication.shared.canOpenURL(url) {
        UIApplication.shared.openURL(url)
      }
    }
    

    telprompt: prompts for call or cancel.

    if let url = URL(string: "telprompt:\(phoneNumber)") {
      if UIApplication.shared.canOpenURL(url) {
        UIApplication.shared.openURL(url)
      }
    }
    

    I didn't know the difference. Question also asks for calling. So this kind of answer would have helped me save time.

提交回复
热议问题