这适用于 MacRuby(需要“安全”框架)
error=SecKeychainAddGenericPassword(
nil,
"someservice".length,
"someservice",
"someusername".length,
"someusername",
"somepassword".length,
"somepassword".pointer,
nil)
在 RubyMotion 中,没有“.pointer”方法,所以我认为必须这样做:
lpointer=Pointer.new(:string)
lpointer.assign("somepassword")
但在 RubyMotion 中,这并不真正将密码存储在钥匙串(keychain)上。 key 创建良好,但其中没有密码。
error=SecKeychainAddGenericPassword(
nil,
"someservice".length,
"someservice",
"someusername".length,
"someusername",
"somepassword".length,
lpointer,
nil)
我错过了什么?
最佳答案
这正在工作
error=SecKeychainAddGenericPassword(
nil,
"someservice".length,
"someservice",
"someusername".length,
"someusername",
"somepassword".length,
"somepassword".dataUsingEncoding(NSUTF8StringEncoding).bytes
nil)
.dataUsingEncoding 从 NSString 生成 NSData,.bytes 生成指向数据的指针。
道德:看起来
.dataUsingEncoding(NSUTF8StringEncoding).bytes
在 RubyMotion 中相当于
.pointer for an NString
关于macos - RubyMotion 中的指针与 MacRuby 中的指针,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18202229/