Macos SecKeychainFindGenericPassword不适用于osx

Macos SecKeychainFindGenericPassword不适用于osx,macos,passwords,keychain,Macos,Passwords,Keychain,下面是我用来获取存储在自定义钥匙链中的密码的一段代码 -(OSStatus *)getPasswordFromKeyChain:(NSString *)username{ OSStatus status; [self createKeyChainIfNotExists]; const char *cService_name = "Mac Google Analytics App"; UInt32 service_length = strlen(cService_name); const c

下面是我用来获取存储在自定义钥匙链中的密码的一段代码

-(OSStatus *)getPasswordFromKeyChain:(NSString *)username{
OSStatus status;

[self createKeyChainIfNotExists];

const char *cService_name = "Mac Google Analytics App";
UInt32 service_length = strlen(cService_name);

const char *cUser_name = [username cStringUsingEncoding:NSUTF8StringEncoding];
UInt32 username_length = strlen(cUser_name);

void *passwordData = nil; 
SecKeychainItemRef itemRef = nil;
UInt32 passwordLength = nil;

status = SecKeychainFindGenericPassword(
                                        mSecKeychainRef,            // default keychain
                                        service_length,  // length of service name
                                        cService_name,    // service name
                                        username_length,// length of account name
                                        cUser_name,    // account name
                                        &passwordLength,  // length of password
                                        passwordData,        // pointer to password data
                                        NULL             // the item reference
                                        );

return status;
}
我想知道这段代码有什么错,因为它从来没有从这个调用中出现过:

SecKeychainFindGenericPassword

它指向了错误。

默认密钥链传递null,您需要一个指向passwordData的指针。这至少会为您提供一个返回状态,告诉您的服务和帐户字符串是否正确

    status = SecKeychainFindGenericPassword(NULL,            // default keychain
                                            service_length,  // length of service name
                                            cService_name,    // service name
                                            username_length,// length of account name
                                            cUser_name,    // account name
                                            &passwordLength,  // length of password
                                            &passwordData,        // pointer to password data
                                            NULL             // the item reference
                                            );

谢谢你的回答。。现在我在passwordData中有了密码。。。如何将其转换为NSString,以便在我的应用程序中进一步使用[[NSString alloc]initWithBytes:passwordData length:passwordLength encoding:NSUTF8StringEncoding];