简体   繁体   English

“NSURLErrorDomain” - 代码:18446744073709550594在Xcode 7上调用Ajax

[英]“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? 我试图从Xcode 7进行异步调用,如下所示,我最终看到此错误“NSURLErrorDomain” - 代码:18446744073709550594当我在Xcode 6中使用它时,这段代码很好。还有其他人看到过这个错误吗?

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. 我尝试使用其他应用程序使用相同的URL,并且它正在正确响应。 I do not see any documentation on this anywhere so posting it here. 我没有在任何地方看到任何文档,所以在这里发布。 Any help would be appreciated. 任何帮助,将不胜感激。

Thank you 谢谢

Nikhil 尼基尔

@Zeuz10 You are right. @ Zeuz10你是对的。 The security in ios9 and later does not allow any http calls to be sent. ios9及更高版本中的安全性不允许发送任何http调用。 To get around the problem, you need to update your Info.plist The instructions are given in this link 要解决此问题,您需要更新Info.plist此链接中提供了相关说明

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

Thank you Zeuz10 for giving me the necessary inputs 谢谢Zeuz10给了我必要的输入

Seems to be a bug, I work around it by keeping under https all requests, hits ios9.0 and 9.0.1 as far as I can tell although you need to allow the url exception as apple documentation suggest in the Info.plist 似乎是一个错误,我通过保持https所有请求来解决它,尽管你需要允许url异常,我可以告诉ios9.0和9.0.1,如Info.plist中的Apple文档建议

ref. REF。 https://developer.apple.com/library/prerelease/ios/technotes/App-Transport-Security-Technote/ https://developer.apple.com/library/prerelease/ios/technotes/App-Transport-Security-Technote/

这只是-999,你可以用NSURLCancel处理它

I got this exact error code when trying to connect to a server with ancient TLS support. 尝试连接到具有古老TLS支持的服务器时,我得到了这个确切的错误代码。 Workaround: add NSExceptionRequiresForwardSecrecy to the app's Info.plist: 解决方法:将NSExceptionRequiresForwardSecrecy添加到应用程序的Info.plist:

<key>NSExceptionDomains</key> 
<dict>
  <key>MY_SERVER_DOMAIN</key>
  <dict>
    <key>NSExceptionRequiresForwardSecrecy</key>
    <false/>
  </dict>
  <!-- any other exceptions you may have -->
</dict>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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