我目前正在开发多个跨平台的应用程序,它们(在iOS下)使用一些共享的密钥链条目。我目前的项目是从安卓开始的,在我们有了一个可用的版本后,我继续开发iOS版本。我从早期的项目中导入了我们的密钥链访问代码,以访问我们共享的登录数据。只是这一次查询总是返回SecStatusCode.ItemNotFound。
我比较了配置文件和授权,它们看起来都是一样的。过了一段时间,它让我抓狂,我创建了一个新的空应用程序,它只有keychain-code、相同的捆绑标识符、配置配置文件和授权文件,就像当前不能工作的应用程序一样,它工作得很好,并返回了我的数据。
对于我的问题,除了entitlements.plist和配置文件之外,还需要配置哪些东西,这些东西可能会干扰我对密钥链条目的访问?因为这个项目有点大,我不想把所有的代码都复制到新的项目中。我尝试了Windows版的Visual Studio 2017和Mac版的VS 2019。这是一个内部/企业应用程序,这是任何人都关心的……
密钥链调用:
KeyChain kc = new KeyChain("USER_DATA", "de.rlp.myCompany.Shared");
var data = kc.Find("LOGIN_DATA");Keychain-Class:
public class KeyChain
{
public string ServiceName { get; set; }
public string GroupName { get; set; }
public KeyChain(string serviceName, string groupName = null)
{
ServiceName = serviceName;
GroupName = groupName;
}
public byte[] Find(string key)
{
SecStatusCode res;
var rec = PrepareDictionary(key);
var match = SecKeyChain.QueryAsRecord(rec, out res);
if (res == SecStatusCode.Success) // ItemNotFound return-code here
{
return match.ValueData.ToArray();
}
else
{
System.Diagnostics.Debug.Write(res.ToString());
}
return null;
}
private SecRecord PrepareDictionary(string key)
{
var sr = new SecRecord(SecKind.GenericPassword)
{
Service = this.ServiceName,
Generic = NSData.FromString (key),
Account = key,
Accessible = SecAccessible.AlwaysThisDeviceOnly
};
if (string.IsNullOrEmpty(GroupName))
{
sr.AccessGroup = GroupName;
}
return sr;
}
}权利-条目
<key>keychain-access-groups</key>
<array>
<string>$(AppIdentifierPrefix)de.rlp.myCompany.Shared</string>
</array>发布于 2019-04-11 22:03:22
https://stackoverflow.com/questions/55628479
复制相似问题