I want to load web view with linkedin authorization url but before loading url was not created stating that it was nil and web view not show any specific page. This is the url string that was passed to URLRequest. https://www.linkedin.com/uas/oauth2/authorization?response_type=code&client_id=*******&redirect_uri=****&state=linkedin1575812567&scope=r_liteprofile
below mention is the code for that.
let responseType = "code"
let state = "linkedin\(Int(NSDate().timeIntervalSince1970))"
var authorizationURL = "\(authorizationEndPoint)?"
authorizationURL += "response_type=\(responseType)&"
authorizationURL += "client_id=\(linkedInConfig.linkedInKey)&"
authorizationURL += "redirect_uri=\(linkedInConfig.redirectURL)&"
authorizationURL += "state=\(state)&"
authorizationURL += "scope=\(scope)"
print(authorizationURL)
let url = URL(string: authorizationURL)
let request = URLRequest(url: url!)
webView.load(request)
URLs can only contain a certain set of characters. Using other characters can cause such errors. Or even the allowed characters can also sometimes cause this, for example, an '&' is used as a delimiter and cannot be directly used in a URL query parameter value.
You can use this for encoding those chaotic characters :
let newURL = YOUR_URL.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)
let url = URL(string: newURL)