Reputation: 111
I'm writing a test app which involves "heavy" keychain access with adding and removing keychain items with different access control attributes and different item types.
This app is very simple - has a text area which serves as a log of what's being written and removed; a button which triggers running the tests. The app has only 1 ViewController class which has the IBAction method for the button. This method holds all of the code that reads/removes the keychain items.
My issue is that the app runs great if it's launched from XCode - when the button's clicked, I get the keychain prompts for TouchID and everything looks good. But, as soon as I launch the app from the Springboard, and click the button, I get the keychain prompt but the app crashes after a few seconds. Examining the logs shows that the cause is "scene-update watchdog transgression: exhausted real time allowance of 10.00 secs".
What am I doing wrong and how different is launching from XCode vs a user launching it?
Evidently, I'm not an experienced developer and would like some help/pointers in the right direction.
Edited to add code: There's just for of valet.set()
or seceureValet.set()
going on.
@IBAction func keychainItemsTest() {
log.text += "Starting read/write..."
valet.removeAllObjects()
secureValet.removeAllObjects()
log.text += "Adding value test1 to keychain"
valet.set(string:"test1", forKey:"test1")
...
}
Upvotes: 1
Views: 2320
Reputation: 415
Your app is being killed because it was unresponsive for too long. Apps launched from Xcode (with a debugger attached) are exempt from launch watchdog timeouts on real hardware.
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.
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.
Upvotes: 2