-
-
Save prashantvc/c5545eee55392aff8b69 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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