我正在尝试使用此 api SecKeychainFindGenericPassword() 获取机场网络密码。 但我总是收到 itemnotfound 错误。我不确定在 API 中的 Account name 和 service name 中传递什么。我添加了代码片段来展示我正在做什么。任何帮助,将不胜感激 。 谢谢
OSStatus status1 ;
SecKeychainRef kychain = nil;
SecKeychainCopyDefault(&kychain);
status1 = SecKeychainFindGenericPassword (
kychain, // default keychain
15, // length of service name
"AirPort Network", // service name
38, // length of account name
"com.apple.network.wlan.ssid.xxxxxxxx", // account name
passwordLength, // length of password
&passwordData, // pointer to password data
itemRef // the item reference
);
return (status1);
我使用的是 osx 10.8
请您参考如下方法:
您已交换服务和帐户。该服务应为 SSID,帐户名应为“AirPort”。
SecKeychainRef keychain;
OSStatus err = SecKeychainOpen("/Library/Keychains/System.keychain", &keychain);
#define kServiceName "com.apple.network.wlan.ssid.Rackus"
#define kAccountName "AirPort"
UInt32 passwordLength = 0;
char* passwordData = nil;
UInt32 serviceNameLength = strlen(kServiceName);
UInt32 accountNameLength = strlen(kAccountName);
SecKeychainItemRef itemRef;
err = SecKeychainFindGenericPassword(keychain, serviceNameLength, kServiceName, accountNameLength, kAccountName, &passwordLength, (void**)&passwordData, &itemRef);