I am pulling my hair out making an attempt to implement what I assumed could be extraordinarily primary: storing key-value pairs within the keychain in a Delphi iOS app. (Within the Maui world it is trivial utilizing SecureStorage, butI’ve discovered no equal wrapper in Delphi. If anybody kknows any, please let me know!)
I’ve gone via the Apple docs, in addition to no matter examples I may discover on-line, however I am caught with an kSecParam error when storing.
Here is among the code I’ve tried to date:
perform SaveToKeychain(const Key, Worth: string) : Boolean;
var
question, attributes: NSMutableDictionary;
standing: OSStatus;
keyData, valueData: NSData;
Knowledge: CFDataRef;
valueBytes : TBytes;
testStr : String;
start
Consequence := False;
strive
question := TNSMutableDictionary.Create;
strive
valueBytes := TEncoding.UTF8.GetBytes(Worth);
//valueData := TNSData.Wrap(TNSData.alloc.initWithBytesNoCopy(@Worth[1], Size(Worth)));
//Knowledge := CFDataCreate(nil, @Worth[1], Size(Worth) * SizeOf(Char));
strive
// Outline the keychain merchandise attributes
question.setValue((kSecClassGenericPassword as ILocalObject).GetObjectID, kSecClass);
question.setValue((StrToNSStr(key) as ILocalObject).GetObjectID, kSecAttrAccount);
//question.setValue(Knowledge, StrToNSStr('kSecValueData'));
question.setValue((StrToNSStr(Worth) as ILocalObject).GetObjectID, StrToNSStr('kSecValueData'));
// Add the merchandise to the keychain
standing := SecItemAdd((question as ILocalObject).GetObjectID, nil);
lastly
CFRelease(Knowledge);
finish;
AddToLog(Format('SaveToKeychain standing: %d', [status]));
Consequence := (standing = errSecSuccess);
lastly
question.Launch;
finish;
besides
on E:Exception do
AddToLog('Error in SaveToKeychain: ' + E.Message);
finish;
finish;
The SecItemAdd name returns a kSecParam error, which suggests a number of of the parameters/attributes is inaccurate. I’ve assumed that it was the info, so I’ve tried a number of methods of including it with no luck.
What am I lacking??