钥匙串未在iOS模拟器11.2中存储数据 [英] key chain not storing data in iOS simulator 11.2

查看:76
本文介绍了钥匙串未在iOS模拟器11.2中存储数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在xamarin c#中编写了以下代码,用于在iPhone钥匙串中存储敏感数据.

I wrote below code in xamarin c# to store sensitive data in iPhone Keychain.

    void StoreKeysInKeychain(string key, string value)
    {

        var user = Settings.CurrentUser;
        var userstring = JsonConvert.SerializeObject(user);

        if (value == "logout")
        {
            userstring = string.Empty;
        };

        var record = new SecRecord(SecKind.GenericPassword)
        {
            ValueData = NSData.FromString(userstring),
            Generic = NSData.FromString(key),
            Label="Sanket",
        };
        SecKeyChain.Remove(record);
        SecKeyChain.Add(record);

    }

    SecRecord GetRecordsFromKeychain(string key)
    {
        SecStatusCode res;
        var rec = new SecRecord(SecKind.GenericPassword)
        {
            Generic = NSData.FromString(key)
        };
        return SecKeyChain.QueryAsRecord(rec, out res);
    }

在另一个MAC模拟器上用相同的代码进行了测试,并且该代码在这里工作,但在我的MAC上却没有.

Tested with the same code on another MAC simulator and it is working there but not on my MAC.

这两个MAC具有相同的iOS 10.13.3和模拟器版本11.2. 甚至我都尝试更改模拟器,但它不存储数据.

Both the MAC has same iOS 10.13.3 and simulator version 11.2. Even I tried to change the simulators but it doesn't store the data.

我试图浏览以sqlite格式存储的钥匙串内容. 请参阅下面的链接,如何浏览模拟器的钥匙串中存储的内容.

I tried to browse Keychain contents stored in sqlite format. Refer below link how to browse content stored in Keychain of simulator.

链接到:浏览存储在模拟器中的钥匙串数据

我试图重置模拟器的内容,但是没有运气.

任何帮助将不胜感激. 谢谢:(

Any help will be appreciated. Thanks :(

推荐答案

在iOS 10中,模拟器上的钥匙串破裂.看看这个Xamarin论坛帖子: https://forums.xamarin.com/discussion/77760/ios-10-keychain 和相关的苹果文章: https://forums.developer.apple.com/thread/51071 .

In iOS 10 keychain on the simulator broke. Check out this Xamarin forums post: https://forums.xamarin.com/discussion/77760/ios-10-keychain and the correlated apple post: https://forums.developer.apple.com/thread/51071.

这是问题所在:问题:除非在Entitlements.plist中启用了启用钥匙串访问组",否则SecKeyChain.Add()在iOS 10模拟器上返回-34018.

Here is the issue: Issue: SecKeyChain.Add() returns -34018 on iOS 10 simulator unless Enable Keychain Access Groups has been enabled in Entitlements.plist.

您需要更新Entitlements.plist以便进行模拟器构建配置.

You need to update your Entitlements.plist for the simulator build configuration.

这篇关于钥匙串未在iOS模拟器11.2中存储数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆