ObjectiveC 中的钥匙串 API,而不是 C?
我是 Cocoa 和 ObjectiveC 的新手,我正在编写一个基本程序,该程序使用 Web 服务让用户登录到网站。我想将凭证存储在钥匙串中,并且我在钥匙串 API 中遇到了 SecKeychainFindGenericPassword。这正是我所需要的,但该示例是用 C 编写的,而不是 ObjectiveC!
我尝试像这样调用它: [SecKeychainFindGenericPassword .. 并且自动完成建议所有参数,但类型是 const char ,而不是 NSString!
ObjectiveC 中也可以使用这个函数吗?有人可以给我看一行调用这个函数的 ObjectiveC 吗?
谢谢你!
x
I'm new to Cocoa and ObjectiveC and I'm writing a basic programme that uses a web service to login a user in to a website. I want to store the credentials in the Keychain and I've come across SecKeychainFindGenericPassword in the Keychain API. It's exactly what I need, but the example is written in C, not ObjectiveC!
I've tried invoking it like this: [SecKeychainFindGenericPassword .. and the autocomplete suggests all the parameters, but the types are const char , not NSString!
Can this function be used in ObjectiveC too? Can someone please show me a line of ObjectiveC that calls this function?
Thank you!
x
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,可以使用该函数,但我建议使用现有的 目标-C 钥匙串包装。当您需要来自
NSString
最简单的方法是使用UTF8String
属性。如果您想指定不同的编码,请使用
- (const char *)cStringUsingEncoding:(NSStringEncoding)encoding
例如,快速谷歌搜索会显示 此示例。
Yes the function can be used but I would recommend using an existing Objective-C keychain wrapper. When you need a C string from an
NSString
the easiest way is to use theUTF8String
property.If you would like to specify a different encoding use
- (const char *)cStringUsingEncoding:(NSStringEncoding)encoding
For an example a quick google search brought up this example.