ios - Retrieve WebVie URL Swift || Cannot assign value of type 'ViewController' to type 'UIWebViewDelegate?' -
i load web page able retrieve current web page after user has logged in , been redirected. have achieved loading of webpage unable retrieve url after user has moved new page. current code have is:
@iboutlet weak var webview: uiwebview! override func viewdidload() { super.viewdidload() // additional setup after loading view, typically nib. needlogin() } func needlogin(){ let url = url(string: "https://www.instagram.com/oauth/authorize/?client_id="+clientid+"&redirect_uri="+redirecturl+"&response_type=token&scope=likes+comments+public_content+follower_list+relationships") let urlrequest = urlrequest(url: url!) webview.loadrequest(urlrequest) self.webview.delegate = self } func webviewdidfinishload(_ webview: uiwebview){ }
the problem have self.webview.delegate = self
. error message :
cannot assign value of type 'viewcontroller' type 'uiwebviewdelegate?'
furthermore have no clue how retrieve url @ , appreciate help.
you need conform uiwebviewdelegate protocol. need
class viewcontroller: uiviewcontroller, uiwebviewdelegate { }
at top of class definition.
to retrieve url after webview has finished loading, within webviewdidfinishload method, need webview.request.url.
disclaimer: should using wkwebview rather uiwebview ios + applications. way example:
import uikit import webkit class webviewcontroller: uiviewcontroller, wknavigationdelegate { var wkwebview : wkwebview? override func viewdidload() { super.viewdidload() needslogin() } func needslogin() { wkwebview = wkwebview.init(frame: self.view.bounds) wkwebview?.navigationdelegate = self self.view.addsubview(wkwebview!) let url = url(string: "https://www.instagram.com/oauth/authorize/? client_id="+clientid+"&redirect_uri="+redirecturl+"&response_type=token&scope=likes+comments+public_content+follower_list+relationships") let urlrequest: urlrequest = urlrequest.init(url: url!) wkwebview?.load(urlrequest) } override func didreceivememorywarning() { super.didreceivememorywarning() // dispose of resources can recreated. } public func webview(_ webview: wkwebview, didfail navigation: wknavigation!, witherror error: error) { print("\(error.localizeddescription)") } public func webview(_ webview: wkwebview, didfinish navigation: wknavigation!) { // url need. let url = webview.url } }
Comments
Post a Comment