iOS Simple Rest API可在模拟器中使用,但不能在任何设备上使用

时间:2018-09-14 13:56:18

标签: ios swift rest

此代码在模拟器iphone 8 Plus上按预期运行,但在以奇怪的结果运行到iphone 8 plus或iphone 6时,此控制台日志失败。 Mac和两台运行当前OS版本的iPhone。

import UIKit

let DomainURL = "http://museum-dev.williams.edu:3003/id?labID="

class artObject : Codable {
    var ObjectID : Int?
    var ObjectName : String?
    var Creators : String?
    var Medium : String?
    var Titles : String?
    var LabelUUID : String?

    static func fetch(withID id : String){
        let urlString = DomainURL + "\(id)"
        print("urlString is \(urlString)")

        if let url = URL(string: urlString) {
            let task = URLSession.shared.dataTask(with: url, completionHandler: { (data,response,error) in
                print(String(data: data!,encoding: .ascii) ?? "no data")

                if let newArtObj = try? JSONDecoder().decode(artObject.self, from: data!) {
                    print(newArtObj.Medium ?? "no url")
                }


            })
            task.resume()
        }
    }
}

class ViewController: UIViewController {


    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
    }

    override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)
        artObject.fetch(withID: "E8EE71C6F5822")
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }


}

urlString为http://museum-dev.williams.edu:3003/id?labID=E8EE71C6F5822

2018-09-14 09:47:45.384385-0400 RestFul[330:16235] [] tcp_timers tcp[1] retransmit SYN 3
2018-09-14 09:47:46.389844-0400 RestFul[330:16235] [] tcp_timers tcp[1] retransmit SYN 4
2018-09-14 09:47:47.395361-0400 RestFul[330:16236] [] tcp_timers tcp[1] retransmit SYN 5
2018-09-14 09:47:49.398078-0400 RestFul[330:16234] [] tcp_timers tcp[1] retransmit SYN 6
2018-09-14 09:47:53.403567-0400 RestFul[330:16236] [] tcp_timers tcp[1] retransmit SYN 7
2018-09-14 09:48:00.098736-0400 RestFul[330:16150] Status bar could not find cached time string image. Rendering in-process.
2018-09-14 09:48:01.409005-0400 RestFul[330:16234] [] tcp_timers tcp[1] retransmit SYN 8
2018-09-14 09:48:17.412384-0400 RestFul[330:16236] [] tcp_timers tcp[1] retransmit SYN 9
2018-09-14 09:49:00.722310-0400 RestFul[330:16520] TIC TCP Conn Failed [1:0x1d4168700]: 1:50 Err(50)
2018-09-14 09:49:00.722701-0400 RestFul[330:16236] Task <5D9E2547-23CE-4959-8CF5-211114B1C533>.<1> finished with error - code: -1001
2018-09-14 09:49:00.724537-0400 RestFul[330:16520] Task <5D9E2547-23CE-4959-8CF5-211114B1C533>.<1> HTTP load failed (error code: -1009 [1:50])

0 个答案:

没有答案