Search code examples
ioskeychain

iOS keychain not restored


I've provided an update for an application that use keychain in iOS. Please note that the update does not have anything to do in the keychain code.

The problem : when some people install the new application, their previous keychain data are not here anymore, at least from the app. point of view I couldn't acces to these people devices so I can't say if the keychain still have this data.

Me : - How I test : I remove the app. I reinstall the app either from Xcode, form itunes, by drag and drop from Finder. - I've tested it successfully on my targets, described below. - I also tried to simulated as closest as possible with a "ad-hoc" profile

=> Results from all this: I always retrieve my previous data

Nota Bene :

The application was originally developped in iOS 3 and now I use Xcode 4 with iOS 4.3 Thus, from Apple :

The keychain data is also backed up.

cf : http://developer.apple.com/library/ios/#documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/RuntimeEnvironment/RuntimeEnvironment.html#//apple_ref/doc/uid/TP40007072-CH2-SW5

__________Targets ____________

People devices with problem: Iphones with iOS 4.3.5 (8L1).

Mine (no problem) : Ipad iOS 4.3.5 (8L1), iPod touch 4.2, simulator


Solution

  • *After many days of rock'n roll with Apple doc,tests, and experimentations I finally understood why there is have different behaviours with keychains.

    The main idea is that, as often with Apple : "all is in certificate", not in code, not in project itself.

    Important for you to know :

    • The keychain access is linked to a certificate, the password grant you to some of data
    • if for historical reasons you have to use more than 1 certificate, you have to create a dedicated entitlements plist that will include all of them cf[1] and beware that older must be 1st in list
    • iOS has 1 keychain (in Mac you can see many with the keychain app)

    Therefore when you use your ad-hoc profile with the good cert. you will be able to read previous saved data again.

    http://useyourloaf.com/blog/2010/4/3/keychain-group-access.html