I am using the keychain with iOS7 as target, I use the attribute : kSecAttrAccessibleWhenUnlockedThisDeviceOnly
It is working great, after 10sec when the device is lock the keychain variables are not accessible.
What I want now is to delete the keychain before the app is killed. applicationWillTerminate
is only called if the app is killed before going into background or if the system release the application. If the app is in background for like 1min before being killed by the user, I can't find how to clear the keychain.
Is there any way to delete the keychain or have a function called when the app is killed by the user after several minute in background ?
Is there any way to delete the keychain...
NO. On iOS, there's only one keychain and its a shared resource.
If interested, here's some reading from the data security point of view. Not much has changed since the iOS 4/5 days. I think the most interesting new things are the NSSecureCoding Protocol for iOS 7 (or was it 6?) and fingerprint authentication.
or have a function called when a app is killed after several minute in background
Yes and no. -applicationWillTerminate
is not sent, despite what the literature says. Instead, you know you are terminating when the SIGKILL
arrives. And you can't trap it. But you may be able to perform a quick wipe and return from the sighandler
, though (I've never tried it, so I don't know).
The strategy to use when the data sensitivity warrants is to begin wiping data when your delegate receives -applicationWillResignActive
. Or start a timer when -applicationWillResignActive
arrives but cancel it if -applicationWillEnterForeground
arrives. If the time elapses, then begin wiping. But both can create a poor user experience.