Well , I try to post data to my server as soon as the app launches with the help of NSURLConnection . Here's my code in swift
let requests : NSMutableURLRequest = NSMutableURLRequest(URL: url)
let useragent : String
if UIDevice.currentDevice().userInterfaceIdiom == UIUserInterfaceIdiom.Phone {
useragent = "iPhone"
}
else {
useragent = "iPad"
}
requests.setValue(useragent, forHTTPHeaderField: "User-Agent")
requests.HTTPMethod = "POST"
requests.setValue("application/json", forHTTPHeaderField: "Content-type")
let jsonstring : String = String(data: urlData, encoding: NSUTF8StringEncoding)!
NSLog("Data being posted to the server")
NSLog("Post Data : Data being posted to server")
requests.timeoutInterval = 60.0
requests.HTTPBody = jsonstring.dataUsingEncoding(NSUTF8StringEncoding)
requests.setValue("\(jsonstring.characters.count)", forHTTPHeaderField: "Content-Length")
let conn : NSURLConnection = NSURLConnection(request: requests, delegate: self)!
conn.isProxy()
I tried printing things in the device logs and the url and the data to be posted (dictionary named json) are all perfect . The logs print these lines successfully as well
NSLog("Data being posted to the server")
NSLog("Post Data : Data being posted to server")
But after this , the app crashes and I could see "Connection invalid " in the device logs . Can anyone help in letting me know if I'm wrong at any point here. Thank you in advance.