Xcode, Swift; How to detect if hyperlink clicked
€8-30 EUR
Paiement à la livraison
I created an iOS app with Xcode and Swift.
In this app there's also an UIWebView loading an URL. All hyperlinks I click there are opened in the WebView itself. But some URLs, if they contain target=external, should get opened external in the Safari browser. I'm doing it with this code:
let url: NSURL = NSURL(string: weburl)!
if [url removed, login to view]("target=external") != nil
{
[url removed, login to view]().openURL(url)
} else {
let requestURL: NSURLRequest = NSURLRequest(URL: url)
[url removed, login to view](requestURL)
}
But to make it work, I'll have to check when a hyperlink is clicked and then run this code.
I tried it as follows:
//
// [url removed, login to view]
// App
//
//
import UIKit
class PushViewController: UIViewController, UIWebViewDelegate {
@IBOutlet var openpushmessage: UIWebView!
var weburl:String = "[url removed, login to view]"
override func viewDidLoad() {
[url removed, login to view]()
let url: NSURL = NSURL(string: weburl)!
let requestURL: NSURLRequest = NSURLRequest(URL: url)
[url removed, login to view](requestURL)
}
override func webView(_ webView: UIWebView, shouldStartLoadWithRequest request: URLRequest, navigationType: UIWebViewNavigationType) -> Bool {
if navigationType == .linkClicked
{
print("You clicked a hypelink!")
}
return true
}
}
But unfortunately I'm getting several warnings as you can see in the attached file.
Who can help me?
Nº du projet : #13039402