0

This code runs as expected on a simulator iphone 8 Plus but fails with this console log when run to an iphone 8 plus or iphone 6 with this odd result. Mac and both iphones running current os versions.

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 is 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])
rmaddy
  • 314,917
  • 42
  • 532
  • 579
user1974376
  • 141
  • 1
  • 8
  • 1
    Did you setup transport security for http loads? – inokey Sep 14 '18 at 14:11
  • Put your device on mobile data and check. – Hasya Sep 14 '18 at 14:32
  • I am all set for now thanks for your suggestions. It's great to see how eager folks are to help. I understand the need to the allow arbitrary loads. My network error was coming from the fact that I had forgotten to enable a necessary VPN on the iPhone when testing on an actual device. – user1974376 Sep 15 '18 at 14:26

1 Answers1

2

Try to set the following keys in your info.plist

<key>NSAppTransportSecurity</key>
<dict>
    <key>NSAllowsArbitraryLoads</key>
    <true/>
</dict>

In production this is not recommended. It will allow your application to call insecure url's. What you want is a valid ssl certificate.

Retterdesdialogs
  • 3,180
  • 1
  • 21
  • 42