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

后端 未结 12 597
囚心锁ツ
囚心锁ツ 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:15

    You need to remember to remove the whitespaces or it won't work:

    if let telephoneURL = NSURL(string: "telprompt://\(phoneNumber.stringByReplacingOccurrencesOfString(" ", withString: ""))") {
            UIApplication.sharedApplication().openURL(telelphoneURL)
        }
    

    "telprompt://" will prompt the user to call or cancel while "tel://" will call directly.

提交回复
热议问题