【问题标题】:Swift NSURLConnection deprecated in iOS 9.0 [duplicate]iOS 9.0 中不推荐使用 Swift NSURLConnection [重复]
【发布时间】:2016-05-15 10:36:04
【问题描述】:

我正在尝试对 api 进行 URL 请求并返回结果。

我在 Swift 2 中使用 NSURLConnection

let requestString = "URL HERE"
let urlPath: String = requestString
        let url: NSURL = NSURL(string: urlPath)!
        let request: NSURLRequest = NSURLRequest(URL: url)
        let connection: NSURLConnection = NSURLConnection(request: request, delegate: self, startImmediately: true)!
        connection.start()

但我不断收到此警告:

'init(request:delegate:startImmediately:)' was deprecated in iOS 9.0: Use NSURLSession (see NSURLSession.h)

我用谷歌搜索了这个警告,但什么也没找到……我该如何解决这个问题?

【问题讨论】:

  • 使用 NSURLSession(见 NSURLSession.h)

标签: ios swift swift2


【解决方案1】:

按照信息告诉你的去做!改用 NSURLSession。它取代了 NSURLConnection,而且要好得多。

【讨论】:

    猜你喜欢
    • 2015-12-26
    • 1970-01-01
    • 2015-12-03
    • 2017-02-06
    • 1970-01-01
    • 2017-07-12
    • 2011-12-13
    • 1970-01-01
    • 2014-08-02
    相关资源
    最近更新 更多