Hello, I am trying to change the following code to work with the new WKWebView as the current one is deprecated in iOS 12.
import UIKit
class IgLoginViewController: UIViewController, UIWebViewDelegate {
@IBOutlet weak var loginWebView: UIWebView!
@IBOutlet weak var loginIndicator: UIActivityIndicatorView!
override func viewDidLoad() {
super.viewDidLoad()
loginWebView.delegate = self
unSignedRequest()
// Do any additional setup after loading the view.
}
func unSignedRequest () {
let authURL = String(format: "%@?client_id=%@&redirect_uri=%@&response_type=token&scope=%@&DEBUG=True", arguments: [INSTAGRAM_IDS.INSTAGRAM_AUTHURL,INSTAGRAM_IDS.INSTAGRAM_CLIENT_ID,INSTAGRAM_IDS.INSTAGRAM_REDIRECT_URI, INSTAGRAM_IDS.INSTAGRAM_SCOPE ])
let urlRequest = URLRequest.init(url: URL.init(string: authURL)!)
loginWebView.loadRequest(urlRequest)
}
func webView(_ webView: UIWebView, shouldStartLoadWith request: URLRequest, navigationType: UIWebView.NavigationType) -> Bool {
return checkRequestForCallbackURL(request: request)
}
func webViewDidStartLoad(_ webView: UIWebView) {
loginIndicator.isHidden = false
loginIndicator.startAnimating()
}
func webViewDidFinishLoad(_ webView: UIWebView) {
loginIndicator.isHidden = true
loginIndicator.stopAnimating()
}
func webView(_ webView: UIWebView, didFailLoadWithError error: Error) {
webViewDidFinishLoad(webView)
}
func checkRequestForCallbackURL(request: URLRequest) -> Bool {
let requestURLString = (request.url?.absoluteString)! as String
if requestURLString.hasPrefix(INSTAGRAM_IDS.INSTAGRAM_REDIRECT_URI) {
let range: Range = requestURLString.range(of: "#access_token=")!
handleAuth(authToken: requestURLString.substring(from: range.upperBound))
return false;
}
return true
}
func handleAuth(authToken: String) {
print("Instagram authentication token ==", authToken)
}
/*
// MARK: - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
// Get the new view controller using segue.destination.
// Pass the selected object to the new view controller.
}
*/
}
Help would be much appreciated, thank you.