ios - How to check an ability of swift to open URL? -
i'm trying images web , can't correctly check validity of url. code:
var url = nsurl(string: self.linkurl) if uiapplication.sharedapplication().canopenurl(url!) { errorlabel.hidden = true println(self.resulturl) self.performseguewithidentifier("save", sender: self) } else { errorlabel.hidden = false }
it works if user pastes "https://www.google.com" doesn't if it's "www.google.com" or "google.com". i've tried:
if var url = nsurl(string: self.linkurl) { errorlabel.hidden = true println(self.resulturl) self.performseguewithidentifier("save", sender: self) } else { errorlabel.hidden = false }
it works if enter "https://www.google.com" on "www.google.com" , "google.com" code breaks further when i'm searching images in html. what's best way make work ?
www.google.com
not valid url, because doesn't include protocol. best way make work check if self.linkurl
starts http://
or https://
(using hasprefix()
), , if not, prepend http://
.
Comments
Post a Comment