Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"NSURLErrorDomain" - code: 18446744073709550594 Ajax call on Xcode 7

I am trying to make an asynchronous call from Xcode 7 as follows and I end up seeing this error "NSURLErrorDomain" - code: 18446744073709550594 This code was fine when I used it in Xcode 6. Has anybody else seen this error?

var task = NSURLSession.sharedSession().dataTaskWithURL(url!, completionHandler: {
            (var data, response, error) -> Void in

            if(response != nil) {
                if (isJSONP){
                    if let prefixData = "(".dataUsingEncoding(NSUTF8StringEncoding, allowLossyConversion: false) {
                        var prefixRange = data!.rangeOfData(prefixData,options:NSDataSearchOptions(), range: NSMakeRange(0, data!.length))
                        if let suffixData = ")".dataUsingEncoding(NSUTF8StringEncoding, allowLossyConversion: false) {
                            var suffixRange = data!.rangeOfData(suffixData, options: NSDataSearchOptions(), range: NSMakeRange(0, data!.length))
                            var jsonRange = NSMakeRange(prefixRange.location + 1, data!.length - prefixRange.location - 3 - suffixRange.length)
                            data = data!.subdataWithRange(jsonRange)
                            json_str = NSString(data: data!, encoding: NSUTF8StringEncoding)!
                            //     println(json_str)
                        }

                    }

                }
                do {
                    let jsonData:AnyObject? = try NSJSONSerialization.JSONObjectWithData(data!, options: .MutableContainers)
                    callback(jsonData: jsonData)
                } catch {
                    print("JSONData not serialized properly or no data exists correctly")
                }

            }// else results not found properly/ trouble accessing server. please try again later
            else {
                var alert = UIAlertController(title: "Alert", message: "Trouble accessing server. Please try again later", preferredStyle: UIAlertControllerStyle.Alert)
                alert.addAction(UIAlertAction(title: "Close", style: UIAlertActionStyle.Default, handler: nil))
                self.presentViewController(alert, animated: true, completion: nil)
            }


        })

        task.resume()

This is the code I have used. I am neither seeing data nor a response. I tried to hit the same url using other applications and it is responding back properly. I do not see any documentation on this anywhere so posting it here. Any help would be appreciated.

Thank you

Nikhil

like image 341
Katakam Nikhil Avatar asked Sep 23 '15 22:09

Katakam Nikhil


1 Answers

@Zeuz10 You are right. The security in ios9 and later does not allow any http calls to be sent. To get around the problem, you need to update your Info.plist The instructions are given in this link

http://ste.vn/2015/06/10/configuring-app-transport-security-ios-9-osx-10-11/

Thank you Zeuz10 for giving me the necessary inputs

like image 105
Katakam Nikhil Avatar answered Sep 21 '22 16:09

Katakam Nikhil