从 Testflight 下载应用程序时,我的 JSON 方法不起作用

My JSON method doesn't work when download app from Testflight

我有 JSON 获取数据的方法。即使我将应用程序从 Xcode 加载到 iPhone,一切都可以在模拟器上运行,但是当我将应用程序上传到 Testflight 进行测试时它不起作用(数据未出现)这是我的获取方法:

private func fetchSchools(){
        let requestURL: NSURL = NSURL(string: "http://somelink.com/json.txt")!
        let urlRequest: NSMutableURLRequest = NSMutableURLRequest(url: requestURL as URL)
        let session = URLSession.shared
        let task = session.dataTask(with: urlRequest as URLRequest) {
            (data, response, error) -> Void in

            let httpResponse = response as! HTTPURLResponse
            let statusCode = httpResponse.statusCode

            if (statusCode == 200) {
                print("Everything is fine, file downloaded successfully.")

                do{

                    let json = try JSONSerialization.jsonObject(with: data!, options:.allowFragments) as! [String: AnyObject]
                    if let JSONSchools = json["skoly"] as? [[String: AnyObject]]{

                        for school in JSONSchools {

                            if let name = school["nazev"] as? String {

                                if let city = school["mesto"] as? String {

                                    if let id = school["id"] as? String {
                                        self.schools.append(School.init(name: name, city: city, id: id))
                                    }

                                }

                            }
                        }
                        self.fetchFinished = true
                    }

                } catch {
                    print("Error with Json: \(error)")
                }
            }
        }

        task.resume()
    }

感谢帮助

我解决了这个问题。它不在 JSON 方法中。我必须:

  1. Select 项目导航器窗格中的项目
  2. Select "PROJECT" 树下的项目设置
  3. 单击"Build Settings" 选项卡
  4. 搜索 "Optimization Level"
  5. 为None设置释放[-O0]