I try to create own links with own actions in a UIWebView. For that I like to read the value of my own links. I manage to do, but I would like someone would have a review on this, because I am not sure if this is best practice ? :-) (messy code ?)
I create my own HTML with some own links like :
let myHTML:String="<a href=\"mylink:" + sLinkValue + "\">" + sDisplayText + "</a>";
I created a UIWebView and show the HTML:
myWebView.loadHTMLString(htmlString, baseURL: noBase);
with a delegate UIWebViewDelegate
my delegate is called when a link is clicked:
func webView(webView: UIWebView!, shouldStartLoadWithRequest request: NSURLRequest!, navigationType: UIWebViewNavigationType) -> Bool {
let requestdescription:String = request.description;
println(requestdescription);
let Valueonly:String=getValueOnly(requestdescription);
println(Valueonly);
return true
}
In above Code my requestdescription
has the following value: <NSMutableURLRequest: 0x7fad4ae21130> { URL: mylink:My%20own%20Value }
and getValueOnly
which cuts and pasts the requestdescription returns "My Own Value
"
Is this the way we should do it ?