简体   繁体   English

无法实现Swift SSLCreateContext

[英]Cannot implement Swift SSLCreateContext

I am new to iOS development, and am trying to implement an SSL connection to a custom port. 我是iOS开发的新手,正在尝试实现与自定义端口的SSL连接。

I found the code from this answer as the best/easiest implementation of a secure connection over a socket https://stackoverflow.com/a/30733961/2306428 我从此答案中找到了代码,它是通过套接字https://stackoverflow.com/a/30733961/2306428进行安全连接的最佳/最简单实现

However, I am getting these errors: 但是,我得到这些错误:

Use of unresolved identifier 'kSSLClientSide' Use of unresolved identifier 'kSSLStreamType' Use of unresolved identifier 'kSSLSessionOptionBreakOnClientAuth'

I have checked and I am running Swift version 2.1.1, using iOS 9.2 SDK and Xcode 7.2. 我已经检查过并使用iOS 9.2 SDK和Xcode 7.2运行Swift版本2.1.1。 I have even tried adding import Security but that has no effect. 我什至尝试添加import Security但这没有效果。

What is the reason that these constants are not being found? 找不到这些常量的原因是什么?

The line being tested is here: https://github.com/ksred/bank-ios/blob/master/Bank/TCPClient.swift#L209 要测试的行在这里: https : //github.com/ksred/bank-ios/blob/master/Bank/TCPClient.swift#L209

Please use the identifiers declared in Swift: 请使用在Swift中声明的标识符:

if let sslContext = SSLCreateContext(kCFAllocatorDefault, SSLProtocolSide.ClientSide, SSLConnectionType.StreamType) {
    SSLSetIOFuncs(sslContext, sslReadCallback, sslWriteCallback)
    SSLSetConnection(sslContext, &socketfd)
    SSLSetSessionOption(sslContext, SSLSessionOption.BreakOnClientAuth, true)
    SSLHandshake(sslContext)
}

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

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