Xcode 9 iOS 11 BoringSSL SSL_ERROR_ZERO_RETURN
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/47802071/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Xcode 9 iOS 11 BoringSSL SSL_ERROR_ZERO_RETURN
提问by Jason Duan
I have a simple program HelloWorld running on iOS. The same code has been running fine for a long time. Recently, I notice that I get the below BoringSSL error when the program runs on my ipad connected to Xcode 9 on my Macbook. I don't see this error when I run the program in simulator. The iOS is 11.2. Xcode is 9.2.
我有一个在 iOS 上运行的简单程序 HelloWorld。相同的代码已经运行了很长时间。最近,我注意到当程序在连接到 Macbook 上的 Xcode 9 的 ipad 上运行时,我收到以下 BoringSSL 错误。当我在模拟器中运行程序时,我没有看到这个错误。iOS是11.2。Xcode 是 9.2。
My code has no reference to BoringSSL. However, it does use NSMutableURLRequest to make https call to a server. The call works fine and everything seems to work fine except the BoringSSL messages.
我的代码没有提到 BoringSSL。但是,它确实使用 NSMutableURLRequest 对服务器进行 https 调用。通话工作正常,除了 BoringSSL 消息外,一切似乎都正常。
Is there a way the I can debug why the message comes up? HellowWorld[466:85961], what do those 2 numbers mean?
有没有办法调试为什么会出现消息?HellowWorld[466:85961],这两个数字是什么意思?
What does the message mean and how to avoid it?
该消息是什么意思以及如何避免它?
2017-12-13 15:41:13.486047-0500 HellowWorld[466:85961] [BoringSSL] Function boringssl_session_errorlog: line 2871 [boringssl_session_read] SSL_ERROR_ZERO_RETURN(6): operation failed because the connection was cleanly shut down with a close_notify alert
2017-12-13 15:41:13.486363-0500 HellowWorld[466:85961] [BoringSSL] Function boringssl_session_errorlog: line 2871 [boringssl_session_read] SSL_ERROR_ZERO_RETURN(6): operation failed because the connection was cleanly shut down with a close_notify alert
回答by l'L'l
Is there a way the I can debug why the message comes up?
有什么方法可以调试消息出现的原因吗?
Yes, there is, and I'm a bit surprised it hadn't been mentioned yet.
是的,有,而且我有点惊讶它还没有被提及。
CFNetwork
handles the core of Foundation
's networking classes — It also has the (often overlooked) capability of detailed logging via the CFNETWORK_DIAGNOSTICS
environment variable.
CFNetwork
处理Foundation
网络类的核心——它还具有(经常被忽视的)通过CFNETWORK_DIAGNOSTICS
环境变量进行详细日志记录的能力。
Programmatically enabling CFNetwork
diagnostic logging:
以编程方式启用CFNetwork
诊断日志记录:
setenv("CFNETWORK_DIAGNOSTICS", "3", 1);
It should be set to an integer value from 0 to 3, where 0 is off and higher numbers give progressively more logging. During normal development you can set this environment variable via Xcode's scheme editor. When the app is run from Xcode, the CFNetwork
log entries will appear in the debug console area (if not visible, choose View
> Debug Area
> Show Debug Area
).
它应该设置为一个从 0 到 3 的整数值,其中 0 表示关闭,数字越大,日志记录越多。在正常开发过程中,您可以通过 Xcode 的方案编辑器设置此环境变量。当应用程序从 Xcode 运行时,CFNetwork
日志条目将出现在调试控制台区域中(如果不可见,请选择View
> Debug Area
> Show Debug Area
)。
The environment variable should be placed right at the beginning of the app's launch sequence. Normally putting this at the start of main is sufficient, but if you have C++ static initialisers that use CFNetwork
you'll have to put it before those.
环境变量应该放在应用程序启动序列的开头。通常把它放在 main 的开头就足够了,但是如果你有 C++ 静态初始化器,CFNetwork
你必须把它放在那些之前。
Note: In Swift this code would go in
main.swift
. By default Swift apps don't have amain.swift
; “The Swift Programming Language” explains how to add one.
*Also note, in Swift remove the semi-colon at the end of thesetenv
.
注意:在 Swift 中,这段代码会放在
main.swift
. 默认情况下,Swift 应用程序没有main.swift
; “The Swift Programming Language”解释了如何添加一个。
*另请注意,在 Swift 中删除setenv
.
Setting the environment variable above should definitely help in determining where the issue is, or at the very least give you a starting point to begin diagnosing a somewhat vague error message.
设置上面的环境变量肯定有助于确定问题所在,或者至少为您提供一个起点,开始诊断有点模糊的错误消息。
回答by AndyC
I managed to fix the issue by adding the "App Transport Security Settings" key to the info.plist. Make sure that "Allow Arbitrary Loads" is set to "Yes".
我设法通过向 info.plist 添加“应用传输安全设置”键来解决这个问题。确保“允许任意加载”设置为“是”。
回答by Florian Pfisterer
For those of you for whom the above methods did not work, this is what the problem was in my case:
对于那些上述方法不起作用的人,这就是我的问题所在:
I was sending a GET
request with a JSON request bodyusing Alamofire. I changed it to a GET
request that contains the parameters as query parameters in the URL instead (along the lines of GET https://your-api.com/v1/request?param=value
). Then it worked flawlessly.
我正在使用Alamofire发送一个GET
带有 JSON请求正文的请求。我将其更改为包含参数作为 URL 中的查询参数的请求(沿着 的行)。然后它完美地工作。GET
GET https://your-api.com/v1/request?param=value
回答by gav
I got a similar message when trying to use NSLog to post a very long list as it would post the list for a long time in the debug console then it so list part of the list followed by a few ...
to show there was more that was not printed in the console, I fixed this (using OBJ-C) and adding this #define to my VC.m
当我尝试使用 NSLog 发布一个很长的列表时,我收到了一条类似的消息,因为它会在调试控制台中发布该列表很长时间,然后它列出了列表的一部分,然后列出了一些列表,...
以显示还有更多不是在控制台中打印,我修复了这个(使用 OBJ-C)并将这个 #define 添加到我的 VC.m
#define NSLog(FORMAT, ...) printf("%s\n", [[NSString stringWithFormat:FORMAT, ##__VA_ARGS__] UTF8String]);
perhaps you can use something similar to your swift project.
也许您可以使用类似于您的 swift 项目的东西。