gpt4 book ai didi

ios - CFDictionaryGetValue 无法使用 CFStringRef 调用

转载 作者:搜寻专家 更新时间:2023-10-31 08:33:26 30 4
gpt4 key购买 nike

我正在尝试实现 CFDictionaryGetValue(),如 this appledoc 中所示 list 3:

server = CFDictionaryGetValue(credentialDict, kSecAttrServer);
userName = CFDictionaryGetValue(credentialDict, kSecAttrAccount);
password = CFDictionaryGetValue(credentialDict, kSecSharedPassword);

我是这样实现的

let userName = CFDictionaryGetValue(credentialDict, kSecAttrAccount)
let password = CFDictionaryGetValue(credentialDict, kSecSharedPassword)

但我收到错误消息“无法使用类型为“(CFDictionaryRef, CFStringRef)”的参数列表调用“CFDictionaryGetValue”

我不明白这与苹果文档的实现方式有何不同。

谢谢

最佳答案

是的,雷达 here 中提到的代码存在问题

我为您找到了解决方法:

  let unsafeCred = CFArrayGetValueAtIndex(credentials, 0)
let credential: CFDictionaryRef = unsafeBitCast(unsafeCred, CFDictionaryRef.self)
let dict: Dictionary<String, String> = credential as! Dictionary<String, String>
let username = dict[kSecAttrAccount as String]
let password = dict[kSecSharedPassword.takeRetainedValue() as! String]

更新

SecRequestSharedWebCredential("www.reddit.com", .None)  {
credentials, error in
if CFArrayGetCount(credentials) > 0 {
let dict = unsafeBitCast(
CFArrayGetValueAtIndex(credentials, 0),
CFDictionaryRef.self) as Dictionary
let username = dict[kSecAttrAccount as String]
let password = dict[kSecSharedPassword as String]
login(username, password)
}
}

请注意这里的区别:

iOS8

var kSecSharedPassword: Unmanaged<AnyObject>!
func SecRequestSharedWebCredential(_ fqdn: CFString!,
_ account: CFString!,
_ completionHandler: ((CFArray!,
CFError!) -> Void)!)

iOS9

let kSecSharedPassword: CFString
func SecRequestSharedWebCredential(_ fqdn: CFString?,
_ account: CFString?,
_ completionHandler: (CFArray?, CFError?) -> Void)

这里是所有的changes适用于 swift2/iOS9/xcode7

关于ios - CFDictionaryGetValue 无法使用 CFStringRef 调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32316037/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com