如何将现有的iOS App升级到Xamarin Forms App

igo*_*gue 7 keychain ios xamarin xamarin.forms

目前,我有一个用Swift编写的iOS应用,将通过Xamarin Forms替换为新版本。我在访问旧的(Swift)钥匙串时遇到麻烦,这ItemNotFound是唯一返回的请求代码。两个应用程序都使用相同的捆绑ID。

这是我正在使用的代码:

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
    };
}
Run Code Online (Sandbox Code Playgroud)

Cha*_*thJ 0

检查 Entitlements.plist 是否设置了启用钥匙串

<dict>
    <key>keychain-access-groups</key>
    <array>
        <string>BUNDLE_ID</string>
    </array>
</dict>
Run Code Online (Sandbox Code Playgroud)

如果它已经在那里了。检查项目的 iOS Bundle Signing(项目 => iOS Bundle Signing)。

您可能必须将“自定义权利”设置为“Entitlement.plist”,因为“自定义权利”的默认设置对于模拟器来说为空。看看这个这个答案。

在此输入图像描述 在此输入图像描述