【发布时间】:2016-08-31 03:35:40
【问题描述】:
我正在尝试使用 TCP SSL 连接 openssl s_server 和 iOS 客户端(另外,我得到了 another issue with this,可能与此相关)。现在我正在尝试使用这个sample code from github:
let mainbun = NSBundle.mainBundle().pathForResource("pd-test", ofType: "cer")
var key: NSData = NSData.dataWithContentsOfMappedFile(mainbun!)! as NSData
var cert:SecCertificateRef =
SecCertificateCreateWithData(kCFAllocatorDefault, key).takeRetainedValue()
var err:OSStatus = noErr
let secDict = NSDictionary(
objects: [kSecClassCertificate,cert],
forKeys: [kSecClass, kSecValueRef]
)
SecItemAdd(secDict as CFDictionaryRef, nil);
但得到错误:
ViewController.swift:67:74: 'AnyObject' is not convertible to 'NSData'; did you mean to use 'as!' to force downcast?
ViewController.swift:69:9: Value of type 'SecCertificate?' has no member 'takeRetainedValue'
ViewController.swift:75:23: Value of type 'CFString' does not conform to expected element type 'NSCopying'
为什么我不能构建有效的代码(我看到很多这样的示例,它们都抛出几乎相同的错误,例如this)?我该如何解决?
【问题讨论】: