How to use openURL for making a phone call in Swift?

后端 未结 12 601
囚心锁ツ
囚心锁ツ 2020-11-30 05:30

I have converted the code for making a phone call from Objective-C to Swift, but in Objective-C, we can set the type of the URL that we like to open (e.g. telephone, SMS, we

12条回答
  •  悲哀的现实
    2020-11-30 06:16

    For making a call in swift, just use the following code: (I have tested it in XCode 11, swift 5)

    let phone = "1234567890"
            if let callUrl = URL(string: "tel://\(phone)"), UIApplication.shared.canOpenURL(callUrl) {
                UIApplication.shared.open(callUrl)
    

提交回复
热议问题