Ich habe Code für die Arbeit Links und TextView könnte bearbeitet werden.Fehler beim Klicken auf eine Telefonnummer oder E-Mail-Adresse in TextView
Und die Links in der Anwendung geöffnet.
Mit Links funktioniert, aber mit (Mail-Adressen, Telefonnummern) funktioniert nicht
Wie kann ich dieses Problem beheben?
Fehler beim Klick auf eine Telefonnummer oder E-Mail-Adresse:
'NSInvalidArgumentException' Grund: ‚Die angegebene URL ein nicht unterstütztes Schema hat. Nur HTTP- und HTTPS-URLs werden unterstützt.
import SafariServices
func textView(_ textView: UITextView, shouldInteractWith URL: URL, in characterRange: NSRange, interaction: UITextItemInteraction) -> Bool {
// Open links with a SFSafariViewController instance and return false to prevent the system to open Safari app
let safariViewController = SFSafariViewController(url: URL)
present(safariViewController, animated: true, completion: nil)
return false
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
NotificationCenter.default.removeObserver(self)
}
@objc func viewTapped(_ aRecognizer: UITapGestureRecognizer) {
self.view.endEditing(true)
}
// when you tap on your textView you set the property isEditable to true and you´ll be able to edit the text. If you click on a link you´ll browse to that link instead
@objc func textViewTapped(_ aRecognizer: UITapGestureRecognizer) {
viewText.dataDetectorTypes = []
viewText.isEditable = true
viewText.becomeFirstResponder()
}
// this delegate method restes the isEditable property when your done editing
func textViewDidEndEditing(_ textView: UITextView) {
viewText.isEditable = false
//viewText.dataDetectorTypes = .all
viewText.dataDetectorTypes = .link
}
Danke soviel) – B2Fq