ストーリーボード未使用で開発しています。
やっていること
下記コードのStringURLには既にStringの"https://www.yahoo.co.jp"を渡しています。
var stringLinkdesu = "リンクです" var hogeTextView = UITextView() var StringURL = String() //"https://www.yahoo.co.jp"を渡しています override func viewDidLoad() { StringURL = "" let attributedString = NSMutableAttributedString(string: stringLinkdesu) attributedString.addAttribute(.link, value:StringURL, range: NSString(string: stringLinkdesu).range(of:"リンク")) hogeTextView.attributedText = attributedString hogeTextView.isEditable = false hogeTextView.isSelectable = true hogeTextView.delegate = self hogeTextView.backgroundColor = .white view.addSubview(hogeTextView) } func textView(_ textView: UITextView, shouldInteractWith URL: URL, in characterRange: NSRange, interaction: UITextItemInteraction) -> Bool { UIApplication.shared.open(URL) let browser = SFSafariViewController(url: URL, entersReaderIfAvailable: true) present(browser, animated: true, completion: nil) return false }
分からないこと
例えばUIApplicationOpenSettingsURLStringを設定して"リンクです"の"リンク"をタップすると問題なくそれには遷移するのですが、
StringURLを設定してタップすると
エラー
'The specified URL has an unsupported scheme. Only HTTP and HTTPS URLs are supported.'
が発生します。
StringURLにはhttpから始まるurlを渡してるので、このエラーの原因が分かりません。
抜けている箇所など、教えていただければ助かります。
よろしくお願いします。
「StringURLを設定してタップすると」←StringURLをどこに設定して何をタップしているのでしょうか?(貼っているコードが質問と関係ないように見えるのですが)
回答1件
あなたの回答
tips
プレビュー