ios – SecItemAdd和SecItemCopyMatching返回错误代码-34018(errSecMissingEntitlement)

ios – SecItemAdd和SecItemCopyMatching返回错误代码-34018(errSecMissingEntitlement),第1张

概述有时,当我从Xcode在设备上运行应用程序时,我会尝试访问钥匙串,但失败,由于错误-34018。这不匹配任何记录的钥匙串错误代码,不能一致重现。 (发生也许30%的时间,我不清楚为什么会发生)。使调试这个问题非常困难的是完全缺乏文档。任何想法是什么原因和如何解决它?我使用Xcode 5并在设备上运行iOS 7.0.4。 这里有一个开放的问题:https://github.com/soffes/ss 有时,当我从Xcode在设备上运行应用程序时,我会尝试访问钥匙串,但失败,由于错误-34018。这不匹配任何记录的钥匙串错误代码,不能一致重现。 (发生也许30%的时间,我不清楚为什么会发生)。使调试这个问题非常困难的是完全缺乏文档。任何想法是什么原因和如何解决它?我使用Xcode 5并在设备上运行iOS 7.0.4。

这里有一个开放的问题:https://github.com/soffes/sskeychain/issues/52

编辑:每个请求添加钥匙串访问代码

我使用SSKeychain库与keychain接口。这里是代码段。

#define SERVICE @"default"@implementation SSKeychain (EXT)+ (voID)setValue:(Nsstring *)value forKey:(Nsstring *)key {    NSError *error = nil;    BOol success = NO;    if (value) {        success = [self setPassword:value forService:SERVICE account:key error:&error];    } else {        success = [self deletePasswordForService:SERVICE account:key error:&error];    }    NSAssert(success,@"Unable to set keychain value %@ for key %@ error %@",value,key,error);    if (!success) {        LogError(@"Unable to set value to keychain %@",error);    }    LogTrace(@"Will set keychain account %@. is to nil? %d",value == nil);    if (value == nil)        LogWarn(@"Setting keychain %@ to nil!!!",key);}+ (Nsstring *)valueForKey:(Nsstring *)key {    NSError *error = nil;    Nsstring *value = [self passwordForService:SERVICE account:key error:&error];    if (error && error.code != errSecItemNotFound) {        NSAssert(!error,@"Unable to retrIEve keychain value for key %@ error %@",error);        LogError(@"Unable to retrIEve keychain value for key %@ error %@",error);    }    return value;}+ (BOol)removeAllValues {    LogInfo(@"Completely reseting Keychain");    return [[self accountsForService:SERVICE] all:^BOol(NSDictionary *accountInfo) {        return [self deletePasswordForService:SERVICE account:accountInfo[@"acct"]];    }];}@end

大多数时候它只是罚款。有时候我会打破断言失败,我不能写或从钥匙串读取,导致严重的断言失败。

解决方法

iOS 10 / XCode 8 Fix:

Add KeyChain EnTitlement,Go to project
settings->CapabilitIEs->Keychain Sharing->Add Keychain Groups+Turn On

这里的答案,从苹果:

UPDATE: We have finally been able to reproduce the -34018 error on iOS
8.3. This is the first step in IDentifying the root cause and then coming up with a fix.

As usual,we can’t commit to a release timeframe,but this has
affected many developers and we really want to get this resolved.

EarlIEr I suggested adding a small delay in
application:dIDFinishLaunchingWithOptions and
applicationDIDBecomeActive: before accessing the keychain as a
workaround. However,that doesn’t actually appear to help. That means
that there’s no kNown workaround at this time other than @R_402_4404@ing
the app.

The issue appears to be related to memory pressure,so perhaps being
more aggressive in handling memory warnings may alleviate the problem

https://forums.developer.apple.com/thread/4743#14441

更新

OK,here’s the latest.
This is a complex problem with multiple
possible causes:

Some instances of the problem are caused by incorrect
app signing. You can easily distinguish this case because the problem
is 100% reproducible. Some instances of the problem are caused by a
BUG in how iOS supports app development (r. 23,991,853). DeBUGging
this was complicated by the fact that another BUG in the OS (r.
23,770,418) masked its effect,meaning the problem only cropped up
when the device was under memory pressure. We belIEve these problems
were resolved in iOS 9.3. We SUSPECT that there may be yet more causes
of this problem.

So,if you see this problem on a user device (one
that hasn’t been talked to by Xcode) that’s running iOS 9.3 or later,
please do file a BUG report about it. Try to include the device
system log in your BUG report (I realise that can be tricky when
dealing with customer devices; one option is to ask the customer to
install Apple Configurator,which lets them vIEw the system log). And
if you do file a BUG,please post your BUG number,just for the
record.

On behalf of Apple I’d like to thank everyone for their
efforts in helPing to track down this rather horrID issue. Share and
Enjoy

https://forums.developer.apple.com/thread/4743#126088

总结

以上是内存溢出为你收集整理的ios – SecItemAdd和SecItemCopyMatching返回错误代码-34018(errSecMissingEntitlement)全部内容,希望文章能够帮你解决ios – SecItemAdd和SecItemCopyMatching返回错误代码-34018(errSecMissingEntitlement)所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1049225.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-25
下一篇 2022-05-25

发表评论

登录后才能评论

评论列表(0条)

保存