钥匙串访问超时

2020-06-02  本文已影响0人  流浪的野兽

问题:

最近接到几例启动卡死,被watchdog kill掉的问题,都在ipad且系统版本为13.4.1上。排查崩溃日志后发现是钥匙串操作问题,例如SecItemAdd调用后无响应。

Termination Reason: Namespace SPRINGBOARD, Code 0x8badf00d 

代表主线程无响应,被watchdog杀掉了

具体原因:

Apple documented not correctly setting access control of the keychain could cause blocking on main thread. We added a new fix in the incoming release to always ensure we correctly set the right access control, instead of default value(kSecAttrAccessibleWhenUnlocked), that is too strict for our use case. We think this might be the reason other than calling it from another thread.

Without any code it's difficult to give you concrete feedback, but my guess is that you're attempting to access the Keychain from the main thread before it's available, locking up the application.

在主线程可用之前从主线程访问keychain,从而锁定了应用程序。

Wait until the applicationProtectedDataDidBecomeAvailable delegate method is called before accessing the keychain. Calls to the keychain are thread-safe in iOS, so you should also be able to perform calls to keychain APIs off the main thread to avoid any blocking requests from locking up your UI.

等待直到调用applicationProtectedDataDidBecomeAvailable委托方法,然后再访问钥匙串。-无法解释为何

在iOS中,对钥匙串的调用是线程安全的,因此您还应该能够在主线程之外执行对钥匙串API的调用,以避免任何阻塞请求锁定您的UI。

It seems that there are circumstances where the security daemon becomes unresponsive。

守护进程无响应。

综上:钥匙串访问本身是线程安全的,虽然耗时但主线程访问本身不会有问题。大概率就是钥匙串相关的安全守护进程无响应,属于iOS系统自身的问题。

解决方案:

钥匙串请求放异步线程,让主线程可执行下去。

作者:senlinwuran

链接:https://juejin.im/post/5ed5c4626fb9a047ee4c4f74

来源:掘金

著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

上一篇下一篇

猜你喜欢

热点阅读