Да, я исправил свою проблему. Что нам нужно сделать, это проверить URL в обратном вызове UITextView, как это.
func textView(_ textView: UITextView, shouldInteractWith URL: URL, in characterRange: NSRange) -> Bool {
if URL.absoluteString == "" { //
self.showTermsCondition(self)
return false
}
return true //System will take care according to URL type, weblink, email or phone number
}
или вы также можете сделать это,
@available(iOS 10.0, *)
func textView(_ textView: UITextView, shouldInteractWith url: URL, in characterRange: NSRange, interaction: UITextItemInteraction) -> Bool {
if (url.scheme?.contains("mailto"))! && characterRange.location > 55{
openMFMail()
}
if (url.scheme?.contains("tel"))! && (characterRange.location > 29 && characterRange.location < 39){
callNumber()
}
return false
}
func callNumber() {
if let phoneCallURL = URL(string: "tel://\(phoneNumber)")
{
let application:UIApplication = UIApplication.shared
if (application.canOpenURL(phoneCallURL))
{
let alert = UIAlertController(title: "Call", message: "\(phoneNumber)", preferredStyle: UIAlertControllerStyle.alert)
if #available(iOS 10.0, *)
{
alert.addAction(UIAlertAction(title: "Call", style: .cancel, handler: { (UIAlertAction) in
application.open(phoneCallURL, options: [:], completionHandler: nil)
}))
}
else
{
alert.addAction(UIAlertAction(title: "Call", style: .cancel, handler: { (UIAlertAction) in
application.openURL(phoneCallURL)
}))
}
alert.addAction(UIAlertAction(title: "cancel", style: .default, handler: nil))
self.present(alert, animated: true, completion: nil)
}
}
else
{
self.showAlert("Couldn't", message: "Call, cannot open Phone Screen")
}
}
func openMFMail(){
let mailComposer = MFMailComposeViewController()
mailComposer.mailComposeDelegate = self
mailComposer.setToRecipients(["\(email)"])
mailComposer.setSubject("Subject..")
mailComposer.setMessageBody("Please share your problem.", isHTML: false)
present(mailComposer, animated: true, completion: nil)
}