在我的MacOS应用程序中,我存储了电子邮件帐户数据,因此5个应用程序密码保存在Keychain中。当应用程序启动时,Keychain要求5次始终允许...有没有办法让Keychain接受我的应用程序一次?例如,Adium存储多个帐户数据,并且在其Keychain中只有一个条目(种类:“Internet密码”)。
代码签名是避免这种情况的唯一方法吗?
商品
+(void)storePasswordKeychainWithPassAndKey:(NSString *)passwordStr:(NSString *)accountNameStr {
const char * accountName = [accountNameStr UTF8String];
const char * password = [passwordStr UTF8String];
OSStatus status;
status = SecKeychainAddGenericPassword(NULL,
strlen(serviceName), serviceName,
strlen(accountName), accountName,
strlen(password), password,
NULL);
}
获取
+(NSString *) getPasswordKeychainWithKey: (NSString *)accountNameStr {
const char * accountName = [accountNameStr UTF8String];
void *password = nil;
UInt32 passwordLen = 0;
SecKeychainItemRef itemRef = nil;
OSStatus status1;
status1 = SecKeychainFindGenericPassword(NULL,
strlen(serviceName), serviceName,
strlen(accountName), accountName,
&passwordLen, &password,
&itemRef);
if (status1 == noErr) {
NSData* passwordData = [NSData dataWithBytes:password length:passwordLen];
SecKeychainItemFreeContent (NULL, password);
return [NSString stringWithCString:[passwordData bytes] encoding:NSUTF8StringEncoding];
}
return nil;
}