adamprocter adamprocter - 1 year ago 92
iOS Question

Json data truncated on cell network ok on wifi

Using the following code to retrieve data via a php file from MySQL works great on wifi but not on mobile it seems to truncate the response. Any help to approach debugging this would be much appreciated. See print outputs pasted into code below for cell v wifi

func get(){

let urlcustom = "\(theteam)"
let url = URL(string: urlcustom)
let data = try? Data(contentsOf: url!)
values = try! JSONSerialization.jsonObject(with: data!, options: JSONSerialization.ReadingOptions.mutableContainers) as! NSArray
print("get ran \(data)")
// mobile phone cell connection - FAIL
// get ran Optional(<5b5d>)

// Wifi Connection
//get ran Optional(<5b7b2269 64223a22 31222c22 7465616d 5f696422 3a223122 2c226e61 6d65223a 22457669 65205072 6f637465 72222c22 646f6222 3a223230 30362d30 312d3033 222c2270 686f746f 223a2222 7d5d>)


Answer Source

I added this to all my files :

header("Content-Type: application/json"); header("Expires: 0"); 
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); 
header("Cache-Control: no-store, no-cache, must-revalidate"); 
header("Cache-Control: post-check=0, pre-check=0", false); 
header("Pragma: no-cache"); 

All works now.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download