In my application, I did Instagram authentication using webView. At first it showed the Instagram login screen, after a successful login I downloaded accessToken, then I got other data using accessToken.
here is my loadrequest method which i call in viewDidLoad
func loadrequest(){ let authURL = String(format: "%@?client_id=%@&redirect_uri=%@&response_type=token&scope=%@", arguments: [INSTAGRAM_API.INSTAGRAM_AUTHURL,INSTAGRAM_API.INSTAGRAM_CLIENT_ID,INSTAGRAM_API.INSTAGRAM_REDIRECT_URI, INSTAGRAM_API.INSTAGRAM_SCOPE ]) let urlRequest = URLRequest.init(url: URL.init(string: authURL)!) instaWebview.loadRequest(urlRequest) }
Here are my webViewDelegate methods where I call the checkRequestForcallBackURL method
func webView(_ webView: UIWebView, shouldStartLoadWith request: URLRequest, navigationType: UIWebViewNavigationType) -> Bool { return checkRequestForcallBackURL(request: request) }
In this method, I check if iam gets my accesstoken or not
func checkRequestForcallBackURL(request : URLRequest) ->Bool{ let requestURLString = (request.url?.absoluteString)! as String if requestURLString.hasPrefix(INSTAGRAM_API.INSTAGRAM_REDIRECT_URI) { let range: Range<String.Index> = requestURLString.range(of: "#access_token=")! handleAuth(authToken: requestURLString.substring(from: range.upperBound)) return false; } return true }
Now, when the login requests a security code, after providing the security code, it redirects me to the Instagram application that I do not want. I do not know how to proceed further
source share