Skip to content

Instantly share code, notes, and snippets.

@prashantvc
Last active August 29, 2015 14:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save prashantvc/c5545eee55392aff8b69 to your computer and use it in GitHub Desktop.
Save prashantvc/c5545eee55392aff8b69 to your computer and use it in GitHub Desktop.
private void SetKeyChainStorage(string theUserID)
{
var rec = new SecRecord (SecKind.GenericPassword){
Generic = NSData.FromString ("active_user_id") //this is the KEY
};
SecStatusCode res;
var match = SecKeyChain.QueryAsRecord (rec, out res);
if (res == SecStatusCode.Success) {
//found the key, so just update the value
var updateTheID = new SecRecord (SecKind.InternetPassword) {
ValueData = theUserID,
Generic = NSData.FromString ("active_user_id")
};
var err = SecKeyChain.Update(match, updateTheID);
if (err != SecStatusCode.Success) {
Console.WriteLine (err.ToString());
}
}
else
//didnt find the key so create it, and set the value
{
var setTheID = new SecRecord (SecKind.GenericPassword) {
ValueData = theUserID,
Generic = NSData.FromString ("active_user_id")
};
var err = SecKeyChain.Add (setTheID);
if (err != SecStatusCode.Success) {
Console.WriteLine ("problem setting theuserID");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment