0

这适用于 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 中,这并没有真正将密码存储在钥匙串上。密钥创建得很好,但其中没有密码。

error=SecKeychainAddGenericPassword(
                              nil,
                              "someservice".length,
                              "someservice",
                              "someusername".length,
                              "someusername",
                              "somepassword".length,
                                    lpointer,
                              nil)

我错过了什么?

4

1 回答 1

1

this is working

error=SecKeychainAddGenericPassword(
                              nil,
                              "someservice".length,
                              "someservice",
                              "someusername".length,
                              "someusername",
                              "somepassword".length,
                              "somepassword".dataUsingEncoding(NSUTF8StringEncoding).bytes
                              nil)

.dataUsingEncoding makes an NSData from an NSString, and .bytes makes a Pointer to the data.

Morality : it seems

.dataUsingEncoding(NSUTF8StringEncoding).bytes

in RubyMotion is equivalent to

.pointer for an NString
于 2013-08-13T22:29:50.380 回答