简体   繁体   中英

Xcode 7 beta NSURLConnection error

I'm calling a function in my server and the app crashes, but it works fine on the simulator. My code:

class func changeTweet(tweet:String)
{
let data = NSMutableData()
let urlPath: String = "http://127.0.0.1:5000/registerword?word=\(tweet)"
let url: NSURL = NSURL(string: urlPath)!
var request = NSMutableURLRequest(URL: url)
let request1: NSURLRequest = NSURLRequest(URL: url)
let response: AutoreleasingUnsafeMutablePointer<NSURLResponse?
>=nil

//crashes on this line:
let dataVal: NSData = try! NSURLConnection.sendSynchronousRequest(request1, returningResponse: response) 

var err: NSErrorPointer
let string = NSString(data: dataVal, encoding: NSUTF8StringEncoding)
if let str = string
{
  print("Server Response: \(str)")
}
}

PS: I already added the keys on the plist

Try this:

let data: NSData = try! NSURLConnection.sendSynchronousRequest(request, returningResponse: &response)

It's the & in front of response that you need I think.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM