I would like to send the deviceToken using NSURL session to my server, but it crashes every time. I've tried to find a way to convert the DataObject (the deviceToken) into NSString but did not succeed so far.
Error: "fatal error: unexpectedly found nil while unwrapping an Optional value"
Any help s greatly appreciated. Here's my code
func application(application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData!) {
let urlPath = "http://example.com/deviceToken=\(deviceToken)"
let url = NSURL(string: urlPath)
let session = NSURLSession.sharedSession()
let task = session.dataTaskWithURL(url!, completionHandler: {data, response, error -> Void in
if(error != nil) {
// If there is an error in the web request, print it to the console
println(error.localizedDescription)
}
var err: NSError?
})
task.resume()
}