0
我有用于提取数据的JSON方法。一切工作的模拟器即使我加载应用程序在Xcode到iPhone,但是当我上传的应用程序进行测试,以Testflight它不工作(数据不会出现),这是我的获取方法:从Testflight下载应用程序时,我的JSON方法不起作用
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()
}
感谢帮助
您正在使用HTTP。你确定,你已经设置了[ATS例外](http://stackoverflow.com/documentation/ios/5435/app-transport-security-ats/19341/load-all-http-content#t=201702260946545609097 )? – FelixSFD
这不是问题。我允许任意加载设置为YES。也许我必须在Capabilities中设置一些东西? – Ender
我解决了这个问题。这不是JSON方法,我不得不将发布优化级别设置为无。 – Ender