linux - IBM Swift 沙盒 : Running NSURLSession: Error running code: unknown error code 132

标签 linux swift nsurlsession ibm-swift-sandbox

我正在尝试执行以下脚本:

import Foundation

class TestURLSession{

var session: NSURLSession!

func run(){
    session = NSURLSession.sharedSession()

    let url = NSURL(string: "http://www.veenex.de/tmp/json")
    let request = NSMutableURLRequest(URL: url!)
    request.setValue("application/json; charset=utf-8", forHTTPHeaderField: "Content-Type")
    request.HTTPMethod = "GET"

    let getDataTask = session.dataTaskWithRequest(request, completionHandler: {(data, response, error) in

        // HTTP Response contains an error
        if let httpResponse = response as? NSHTTPURLResponse {
            if httpResponse.statusCode != 200 {
                print("response was not 200: \(response)")
                return
            }
        }

        // Error submitting Request
        if error != nil {
            print("error submitting request: \(error)")
            return
        }

        // print data
        if data != nil{

            do {
                let json = try NSJSONSerialization.JSONObjectWithData(data!, options: NSJSONReadingOptions.MutableContainers) as! NSArray

                for entry in json {
                    print(entry)
                }

            } catch {
                print("Error printing data")
            }

        }


    });

    getDataTask.resume()
}

}

let testURLSession = TestURLSession()
testURLSession.run()

但我收到错误消息:“错误运行代码:未知错误代码 132。”。 在 Xcode Playground 中执行代码即可。

最佳答案

尚未编写 NSURLSession 的纯 Swift 实现。查看NSURLSession.swift在 Apple 的 GitHub 存储库中为 Foundation 提交文件。

每个方法都是 NSUnimplemented(),这意味着它还没有被实现。在完成本类(class)之前,它将无法在 Linux 和 IBM 的 Swift Sandbox 上使用。

关于linux - IBM Swift 沙盒 : Running NSURLSession: Error running code: unknown error code 132,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34926159/

相关文章:

ios - HTTP 请求在 swift 中不起作用

swift - 如何从包含 DataTask 的方法返回对象

linux - 如何找到Linux系统的虚拟内存大小和缓存大小?

ios - Swift - 将 pickerView 添加到 UIViewController 中的文本字段

ios - Swift 中的内存管理 : memory don't released after NSOperation ends

ios - 有什么方法可以强制 UILocalNotification 默认为警报?

linux - nasm,读取系统调用读取缓冲区大小

c++ - cpp 程序中出现意外错误?

c++ - 无法使用 Eigen 库进行编译

ios - swift 错误 : ambiguous reference to member 'jsonObject(with:options:)