Why don't the iOS keychain values ​​change without exiting the ViewController?

I have an abstraction in the IOS Keychain API that seems to work well. Basically, it has:

public string GetGenericPasswordField(string account)
{
    var record = SecKeyChain.QueryAsRecord(query, out code);
    if (code == SecStatusCode.ItemNotFound)
        return null;
    return NSString.FromData(record.ValueData, NSStringEncoding.UTF8);
}

public void SetGenericPasswordField(string account, string value)
{
    if (value == null)
    {
        SecKeyChain.Remove(record);
        return;
    }
    var record = new SecRecord (SecKind.GenericPassword) {
        Service = service,
        Label = label,
        Account = account,
        ValueData = NSData.FromString (value),
    };
    SecStatusCode code = SecKeyChain.Add (record);
    if (code == SecStatusCode.DuplicateItem)
    {
        // (remove and re-add item)
    }
}

      

I used this abstraction in the application settings screen to save the values ​​on exit and then load those values ​​elsewhere in the application.

But I ran into a problem where saving the value does not take effect unless you leave the current ViewController. What I am doing is similar:

if (Keychain.GetGenericPasswordField("RemoteLogin") == null)
{
    var remotePassword = GetFromDialog();
    Keychain.SetGenericPasswordField("RemoteLogin", Hash(remotePassword));
    // Safe to assume the RemoteLogin password got saved, right?
}

// Later on...

if (Keychain.GetGenericPasswordField("RemoteLogin") == null)
{
    // This block is being executed
}

      

I went through the code in the debugger to confirm that things are happening as I describe them, and that my abstraction method does indeed return SecStatusCode.ItemNotFound

back, which means that null is an appropriate value to return.

I worked on this one day by moving the first half of my code back to the previous ViewController and for some reason seemed to wake it up or clear all caching. But now I am faced with another situation where it is not very practical.

Why is this happening? Is my abstraction happening?

+3
ios iphone xamarin.ios


source to share


No one has answered this question yet

Check out similar questions:

24
Keychain: Item specified as errSecItemNotFound but receives errSecDuplicateItem when added
17
Reading PEM public key in iOS
4
Passing Data Between View Controllers Using Protocol and Delegation
4
Value stored in keychain in Objective-C cannot be retrieved in Swift?
1
Long iOS strings stored in keychain get accidentally damaged
1
How do I get the return value of the viewcontroller and compare the NSString?
0
passing let value between classes / viewcontrollers in swift
0
avoid transition error to navigate with view controller id
0
pass information from model to viewController without NSNotification
0
Does Firebase use a token in iOS apps?



All Articles
Loading...
X
Show
Funny
Dev
Pics