【问题标题】:Web View Not loading with url request and URL show nilWeb 视图未加载 url 请求和 URL 显示 nil
【发布时间】:2019-12-09 18:59:14
【问题描述】:

我想用linkedin 授权url 加载web 视图,但在加载之前没有创建url,说明它是nil 并且web 视图不显示任何特定页面。 这是传递给 URLRequest 的 url 字符串。 https://www.linkedin.com/uas/oauth2/authorization?response_type=code&client_id=*******&redirect_uri=****&state=linkedin1575812567&scope=r_liteprofile

下面提到的是代码。

    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)

【问题讨论】:

  • 您是否正确实现了 Web 视图委托?很难从您的代码中理解可能是什么问题。
  • 我正确设置了navigationdelegate。但它什么也没做。

标签: ios swift linkedin


【解决方案1】:

URL 只能包含特定的字符集。使用其他字符可能会导致此类错误。甚至允许的字符有时也会导致这种情况,例如,“&”用作分隔符,不能直接用于 URL 查询参数值中。

你可以用它来编码那些混乱的字符:

let newURL = YOUR_URL.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)
let url = URL(string: newURL)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-11-01
    • 2023-03-31
    • 2015-12-12
    • 1970-01-01
    • 2014-06-06
    • 2013-09-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多