iOS的钥匙链不检索从背景值 [英] iOS KeyChain not retrieving values from background

查看:193
本文介绍了iOS的钥匙链不检索从背景值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前存储的用户名(电子邮件)和iOS的钥匙串中的电子邮件和密码的哈希盐渍。我使用ARC'ified版本发现 href=\"https://gist.github.com/1170641\">。

I am currently storing the username (email) and a salted hash of the email and password in the iOS KeyChain. I'm using the ARC'ified version found here.

KeychainItemWrapper *wrapper = [[KeychainItemWrapper alloc] initWithIdentifier:@"MyCustomIdentifier" accessGroup:nil];
[wrapper setObject:APP_NAME forKey:(__bridge id)kSecAttrService];
[wrapper setObject:email forKey:(__bridge id)kSecAttrAccount];
[wrapper setObject:token forKey:(__bridge id)kSecValueData];

当我需要拉出来令牌为我的网络调用,而应用程序是活跃的这一切工作正常。它适用于从干净启动登录,以及所有的网络遍布调用。当应用程序在后台的麻烦开始。

This all works fine when I need to pull the token out for my network calls while the app is active. It works for logging in from a clean startup, as well as all the network calls throughout. The trouble starts when the app is in the background.

请记住,这只是发生零星的,我还没有针下来到一个特定的IOS版本或设备。

Keep in mind, this only happens sporadically and I have yet to pin it down to a specific iOS version or device.

用户出游的地点(区域监控),我想更新其状态的服务器。我试着拉令牌出来的钥匙圈,以同样的方式为我所有其他网络呼叫做的,和更新状态。但对于一些用户来说,价值为零。没有它,我不能更新网络的东西。为什么将这项工作对于大多数,但不是一个很小的比例?

The user trips a location (region monitoring) and I want to update the server with their status. I try to pull the token out of the keychain, the same way I do for every other network call, and update the status. But for some users, the value is nil. Without it, I can't update the network stuff. Why would this work for most, but not for a small percentage?

KeychainItemWrapper *wrapper = [[KeychainItemWrapper alloc] initWithIdentifier:@"MyCustomIdentifier" accessGroup:nil];
NSString *token = [wrapper objectForKey:(__bridge id)kSecValueData];

我又回到了keychainwrapper的非ARC版本,但我仍然得到同样的结果。我想AP preciate这个任何反馈。这仅仅是我的用户的一小部分,但它是我想解决,而不是担心的问题。先谢谢了。

I've gone back to the non-ARC version of the keychainwrapper, but I still get the same results. I would appreciate any feedback on this. It is only a small part of my users, but it is an issue I would like to fix and not worry about. Thanks in advance.

此外,所有我的工作背景是在一个backgroundTask超时设置为prevent的事情。我不与周围的钥匙串工作的任何问题,但我不让事情往前走,直到我的令牌被填满。

Also, all of my background work is set up in a backgroundTask to prevent things from timing out. I'm not having any issues with the work surrounding the keychain, but I don't let things go forward until my token is filled.

修改
我已经想通了我的问题与他们没有钥匙扣从后台检索值。我会后下面的答案,并接受它,因为我觉得这个问题可能会成为宝贵他人更高版本。

EDIT I've figured out my issue with they keychain not retrieving values from the background. I will post the answer below and accept it as I feel this question may become valuable to others later.

推荐答案

我的问题是接近大关原因,但并不完全。通过博客后博客看完后,教程教程后,我终于找到了一个散发出什么可能发生的一个暗示。

My question was close to the mark for the reason why, but not quite. After reading through blog after blog, tutorial after tutorial, I finally found one that gave off a hint of what might be happening.

锁定主屏幕。钥匙串教程永远离开了辅助功能设置为空白的钥匙串,所以它会默认为苹果公司的最低/最安全访问级别。此级别但不允许钥匙串访问用户是否有锁屏上一通code。答对了!这解释了零星的行为和为什么这仅发生在用户的一个小的百分比

Locked home screens. The keychain tutorials always left the accessibility settings for the keychain blank, so it would default to Apple's lowest/safest access level. This level however doesn't allow keychain access if the user has a passcode on the lock screen. Bingo! This explains the sporadic behavior and why this only happens to a small percentage of users.

code一号线,解决了整个一团糟。

One line of code, solves the entire mess.

[wrapper setObject:(__bridge id)kSecAttrAccessibleAlways forKey:(__bridge id)kSecAttrAccessible];

添加此行,其中我设置的用户名和密码值。奇迹般有效。希望这将有助于有人在那里。它混淆了我相当长一段时间,直到我能够把碎片在一起。

Add this line where I'm setting the username and password values. Works like a charm. Hope this will help someone out there. It confounded me for quite a while until I was able to put the pieces together.

这篇关于iOS的钥匙链不检索从背景值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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