How To Upgrade Existing iOS App to a Xamarin Forms App
Asked Answered
I

1

7

Currently, I have an iOS app written in Swift that will be replaced by a new version via Xamarin Forms. I am having trouble accessing the old (Swift) Keychain, where ItemNotFound is the only request code returned. Both apps are using the same Bundle ID.

Here's the code I'm using:

byte[] _LegacyGetKeychainItem<T>(string key)
{
    using (var record = ExistingRecordForKey(key))
    using (var match = SecKeyChain.QueryAsData(record, false, out var resultCode))
    {
        if (resultCode == SecStatusCode.Success)
        {
            return match.ToArray();
        }
    }

    throw new InvalidOperationException(string.Format("GetKeychainItem: data was null for key: {0}", key));
}

SecRecord ExistingRecordForKey(string key)
{
    return new SecRecord(SecKind.GenericPassword)
    {
        Service = SEC_SERVICE, // Same as Bundle ID
        Account = key
    };
}
Ionopause answered 27/8, 2019 at 18:24 Comment(6)
Why is this tagged Android? Have you deleted the old app? Or did you install the new app with the same bundle id on top of the old app? What code are you using to access the Keychain? What errors or exceptions are you getting?Botanize
Here is an article , maybe helpful .riptutorial.com/xamarin-ios/example/8337/using-keychainDevoted
@Botanize I updated the question, removed the android tag and added some of my codeIonopause
@igorgue: Have you checked the Entitlements.plist for Keychain enablement?Troublemaker
@Troublemaker Yeah they are the same...Ionopause
Have you selected the plist for the correct configuration as I have shown in the screenshot?Troublemaker
T
0

Check if Entitlements.plist have the Enable Keychain set

<dict>
    <key>keychain-access-groups</key>
    <array>
        <string>BUNDLE_ID</string>
    </array>
</dict>

If it's already there. Check your project's iOS Bundle Signing (Project => iOS Bundle Signing).

You may have to set "Custom Entitlements" as "Entitlement.plist", because default setting for "Custom Entitlements" is empty for simulators. Have a look at this and this answers.

enter image description here enter image description here

Troublemaker answered 3/9, 2019 at 1:45 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.